[Paper Review] Prompt Engineering or Fine-Tuning: An Empirical Assessment of LLMs for Code
This study compares GPT-4 prompting strategies with fine-tuned LLM baselines across comment generation, code generation, and code translation, including a qualitative user study on conversational prompting with GPT-4.
The rapid advancements in large language models (LLMs) have greatly expanded the potential for automated code-related tasks. Two primary methodologies are used in this domain: prompt engineering and fine-tuning. Prompt engineering involves applying different strategies to query LLMs, like ChatGPT, while fine-tuning further adapts pre-trained models, such as CodeBERT, by training them on task-specific data. Despite the growth in the area, there remains a lack of comprehensive comparative analysis between the approaches for code models. In this paper, we evaluate GPT-4 using three prompt engineering strategies -- basic prompting, in-context learning, and task-specific prompting -- and compare it against 17 fine-tuned models across three code-related tasks: code summarization, generation, and translation. Our results indicate that GPT-4 with prompt engineering does not consistently outperform fine-tuned models. For instance, in code generation, GPT-4 is outperformed by fine-tuned models by 28.3% points on the MBPP dataset. It also shows mixed results for code translation tasks. Additionally, a user study was conducted involving 27 graduate students and 10 industry practitioners. The study revealed that GPT-4 with conversational prompts, incorporating human feedback during interaction, significantly improved performance compared to automated prompting. Participants often provided explicit instructions or added context during these interactions. These findings suggest that GPT-4 with conversational prompting holds significant promise for automated code-related tasks, whereas fully automated prompt engineering without human involvement still requires further investigation.
Motivation & Objective
- Assess the effectiveness of GPT-4 under automated prompting strategies (basic, in-context, task-specific) versus fine-tuned LLM baselines on ASE tasks.
- Evaluate three ASE tasks: comment generation (SC to NL), code generation (NL to SC), and code translation (SC to SC).
- Explore how participants perceive and evolve prompts in conversational GPT-4 interactions for ASE tasks.
- Investigate whether fully automated prompt engineering can outperform fine-tuning and identify gaps for human-in-the-loop prompting.
Proposed method
- Quantitative comparison using CodeXGLUE, HumanEval, and MBPP benchmarks to evaluate GPT-4 under three prompting strategies against publicly available fine-tuned baselines.
- Three prompting strategies: basic prompting, in-context learning with BM25-based example selection, and task-specific engineered prompts.
- Use BLEU, pass@1, ACC, and CodeBLEU as task-specific evaluation metrics.
- Post-processing and tokenization adjustments to ensure fair evaluation across tasks.
- Qualitative user study with 27 graduate students and 10 industry practitioners to analyze conversational prompting and prompt evolution patterns.
Experimental results
Research questions
- RQ1RQ1: How effective is GPT-4 under different prompting strategies compared to fine-tuned baselines across the three ASE tasks.
- RQ2RQ2: How do participants perceive the usefulness of GPT-4 with a basic prompt in the ASE tasks.
- RQ3RQ3: How do participants refine prompts when interacting with GPT-4 for ASE tasks.
- RQ4RQ4: What is the impact of different prompt evolution patterns on GPT-4’s ASE task performance.
Key findings
- GPT-4 with the best prompting strategy outperformed the first-ranked fine-tuned model by 8.33 BLEU points on average for comment generation.
- For code generation, the first-ranked fine-tuned model outperformed GPT-4 with best prompting by 16.61 and 28.3 BLEU points on average.
- GPT-4 and fine-tuned baselines tie in code translation, with each outperforming the other on different translation tasks.
- Conversational prompting with GPT-4 yielded significant performance gains over automated prompting strategies across all three ASE tasks (15.8%, 11.83%, and 16.1% improvements in respective tasks).
- Qualitative results indicate humans provide useful feedback, context, and instructions that substantially enhance GPT-4 outputs, highlighting the potential of human-in-the-loop prompting.
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.