[Paper Review] Fine-Tuning and Prompt Engineering for Large Language Models-based Code Review Automation
This study investigates the impact of few-shot learning, prompt engineering (including persona patterns), and fine-tuning on GPT-3.5 for code review automation. Results show that fine-tuning significantly outperforms zero-shot and few-shot inference, while persona inclusion degrades performance, leading to recommendations to use few-shot prompting and fine-tuning without personas for optimal code generation.
Context: The rapid evolution of Large Language Models (LLMs) has sparked significant interest in leveraging their capabilities for automating code review processes. Prior studies often focus on developing LLMs for code review automation, yet require expensive resources, which is infeasible for organizations with limited budgets and resources. Thus, fine-tuning and prompt engineering are the two common approaches to leveraging LLMs for code review automation. Objective: We aim to investigate the performance of LLMs-based code review automation based on two contexts, i.e., when LLMs are leveraged by fine-tuning and prompting. Fine-tuning involves training the model on a specific code review dataset, while prompting involves providing explicit instructions to guide the model's generation process without requiring a specific code review dataset. Method: We leverage model fine-tuning and inference techniques (i.e., zero-shot learning, few-shot learning and persona) on LLMs-based code review automation. In total, we investigate 12 variations of two LLMs-based code review automation (i.e., GPT- 3.5 and Magicoder), and compare them with the Guo et al.'s approach and three existing code review automation approaches. Results: The fine-tuning of GPT 3.5 with zero-shot learning helps GPT-3.5 to achieve 73.17% -74.23% higher EM than the Guo et al.'s approach. In addition, when GPT-3.5 is not fine-tuned, GPT-3.5 with few-shot learning achieves 46.38% - 659.09% higher EM than GPT-3.5 with zero-shot learning. Conclusions: Based on our results, we recommend that (1) LLMs for code review automation should be fine-tuned to achieve the highest performance; and (2) when data is not sufficient for model fine-tuning (e.g., a cold-start problem), few-shot learning without a persona should be used for LLMs for code review automation.
Motivation & Objective
- To investigate the impact of few-shot learning, prompt design (including persona patterns), and model fine-tuning on GPT-3.5 for code review automation.
- To compare the performance of GPT-3.5 using different prompting strategies and fine-tuning against existing deep learning-based code review automation approaches.
- To identify optimal configurations for deploying GPT-3.5 in real-world code review pipelines.
- To evaluate the effectiveness of prompt engineering and few-shot examples in improving code generation quality.
- To determine whether fine-tuning GPT-3.5 on a small dataset yields measurable improvements in code quality metrics like Exact Match and CodeBLEU.
Proposed method
- Constructed input prompts with few-shot examples selected using the BM25 algorithm to improve zero-shot generalization.
- Incorporated persona patterns into prompts to simulate reviewer roles, testing their influence on output quality.
- Fine-tuned GPT-3.5 on a small, randomly sampled subset of training data to adapt the model to code review tasks.
- Evaluated model performance using two standard metrics: Exact Match (EM) and CodeBLEU on three public code review datasets: Tufano, D-ACT, and CodeReviewer.
- Compared zero-shot, few-shot, and fine-tuned GPT-3.5 performance against existing deep learning-based code review automation systems.
- Used consistent prompt templates and hyperparameters across experiments to ensure comparability, following OpenAI’s prompt design guidelines.

Experimental results
Research questions
- RQ1RQ1: What is the impact of few-shot learning on GPT-3.5 for code review automation compared to zero-shot inference?
- RQ2RQ2: How does including a persona in input prompts affect GPT-3.5’s performance in generating improved code?
- RQ3RQ3: How does model fine-tuning influence GPT-3.5’s performance relative to zero-shot and few-shot settings?
- RQ4RQ4: How does fine-tuned GPT-3.5 compare to existing code review automation approaches in terms of code quality metrics?
Key findings
- Few-shot learning improved GPT-3.5’s Exact Match by at least 46.38% and CodeBLEU by at least 3.97% compared to zero-shot inference.
- Including a persona in input prompts reduced Exact Match by at least 1.02% and CodeBLEU by at least 0.15% compared to prompts without personas.
- Fine-tuned GPT-3.5 achieved at least 9.74% higher Exact Match and 0.12% higher CodeBLEU than both zero-shot and few-shot settings.
- Fine-tuned GPT-3.5 outperformed existing code review automation approaches by at least 11.48% in Exact Match across all datasets.
- The highest performance was consistently achieved by fine-tuned GPT-3.5 across all three datasets, especially for higher numbers of changed tokens.
- For the Tufano dataset without comments, few-shot learning slightly outperformed fine-tuning, but fine-tuned GPT-3.5 remained superior overall.

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.