Research Article

An empirical study of prompt mode in code generation based on ChatGPT

Huaiyu Guo*
Capital University of Economics and Business

* Corresponding author: [email protected]

Abstract

In recent years, with the continuous advancement of technologies such as Large Language Models (LLMs) and Chat Generative Pre-trained Transformer (ChatGPT), an increasing number of developers have turned to AI-assisted code generation. However, in the context of code generation, simple question-and-answer approaches may not yield the desired results. To address this challenge, we introduce prompt engineering as a means to construct efficient prompting methods for guiding models in generating the intended code. This paper empirically explores the impact of different prompting methods on code-generation tasks. We introduce several prompt-sensitive code tasks in our experiments and assess the effectiveness of various prompt methods in terms of the quality of generated code. Ultimately, we find that guiding the model from a specific role perspective yields the best results, while other methods exhibit varying degrees of effectiveness. This research provides valuable insights into the application of prompt engineering in code generation, encouraging future efforts to further optimize prompting methods and enhance the accuracy and practicality of generated code.

Keywords: Large Language Model; ChatGPT; Prompt Engineering; Code Generation
Published: July 5, 2024
DOI: 10.54254/2755-2721/73/20240367
Volume: ACE Vol.73
pp. 69-76
Download PDF

References

  1. Zhao, W. X., Zhou, K., Li, J., Tang, T., Wang, X., Hou, Y., ... & Wen, J. R. (2023). A survey of large language models. arXiv preprint arXiv:2303.18223.
  2. Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I. (2017). Attention is all you need. Advances in neural information processing systems, 30.
  3. Radford, A., Narasimhan, K., Salimans, T., & Sutskever, I. (2018). Improving language understanding by generative pre-training.
  4. Radford, A., Wu, J., Child, R., Luan, D., Amodei, D., & Sutskever, I. (2019). Language models are unsupervised multitask learners. OpenAI blog, 1(8), 9.
  5. Brown, T., Mann, B., Ryder, N., Subbiah, M., Kaplan, J. D., Dhariwal, P., ... & Amodei, D. (2020). Language models are few-shot learners. Advances in neural information processing systems, 33, 1877-1901.
  6. Kojima, T., Gu, S. S., Reid, M., Matsuo, Y., & Iwasawa, Y. (2022). Large language models are zero-shot reasoners. Advances in neural information processing systems, 35, 22199-22213.
  7. Gao, L., Madaan, A., Zhou, S., Alon, U., Liu, P., Yang, Y., ... & Neubig, G. (2023, July). Pal: Program-aided language models. In International Conference on Machine Learning (pp. 10764-10799). PMLR.