[Paper Review] Improving ChatGPT Prompt for Code Generation
The paper shows that carefully designed prompts with chain-of-thought and multi-step optimizations significantly improve ChatGPT's text-to-code and code-to-code generation on CodeXGlue, and analyzes factors like conciseness, session context, and randomness.
Automated code generation can be a powerful technique for software development, significantly reducing developers' efforts and time required to create new code by generating it automatically based on requirements. Recently, OpenAI's language model ChatGPT has emerged as a powerful tool for generating human-like responses to a wide range of textual inputs (i.e., prompts), including those related to code generation. However, the effectiveness of ChatGPT for code generation is not well understood, and the generation performance could be heavily influenced by the choice of prompt. To answer these questions, we conducted experiments using the CodeXGlue dataset to evaluate ChatGPT's capabilities for two code generation tasks, including text-to-code and code-to-code generation. We designed prompts by leveraging the chain-of-thought strategy with multi-step optimizations. Our results showed that by carefully designing prompts to guide ChatGPT, the generation performance can be improved substantially. We also analyzed the factors that influenced the prompt design and provided insights that could guide future research.
Motivation & Objective
- Evaluate ChatGPT's code generation performance on two tasks (text-to-code and code-to-code) using CodeXGlue.
- Investigate prompt engineering techniques to guide ChatGPT via chain-of-thought and multi-step optimizations.
- Identify factors influencing prompt design and provide actionable insights for future research.
Proposed method
- Use CodeXGlue to assess ChatGPT on T2C and C2C tasks.
- Design prompts with manual chain-of-thought based multi-step optimizations (P1–P5).
- Evaluate prompts with BLEU and CodeBLEU metrics and analyze improvements.
- Test baselines: ChatGPT-task, ChatGPT-detail, ChatGPT-behaviour.
- Explore conciseness, session, and generation randomness effects.
- Compare ChatGPT with fine-tuned LLMs on CodeXGlue.
Experimental results
Research questions
- RQ1RQ1: How effective are the designed prompts for ChatGPT on T2C and C2C tasks?
- RQ2RQ2: How does requesting conciseness affect ChatGPT-generated code?
- RQ3RQ3: How does session (continuous vs. individual) setting impact ChatGPT outputs?
- RQ4RQ4: How does generation randomness influence ChatGPT code quality and consistency?
Key findings
- Prompt design substantially improves both T2C and C2C performance (e.g., BLEU and CodeBLEU gains over baselines).
- Conciseness requests improve T2C results (BLEU and CodeBLEU) but have mixed effects on C2C.
- Continuous sessions help C2C but not T2C, while individual sessions are better for T2C in this setup.
- Generation randomness has little effect under the designed prompts, showing stable results across runs.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.