[论文解读] Fine-Tuning and Prompt Engineering for Large Language Models-based Code Review Automation
本研究探讨了少样本学习、提示工程(包括角色模式)以及微调对 GPT-3.5 在代码审查自动化中的影响。结果表明,微调显著优于零样本和少样本推理,而角色模式的引入则降低了性能,因此建议在实现最优代码生成时采用少样本提示与无角色模式的微调。
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.
研究动机与目标
- 探究少样本学习、提示设计(包括角色模式)以及模型微调对 GPT-3.5 在代码审查自动化中影响。
- 将使用不同提示策略和微调的 GPT-3.5 与现有的基于深度学习的代码审查自动化方法进行性能比较。
- 确定在真实代码审查流水线中部署 GPT-3.5 的最优配置。
- 评估提示工程与少样本示例在提升代码生成质量方面的有效性。
- 确定在小规模数据集上微调 GPT-3.5 是否能显著提升代码质量指标(如精确匹配和 CodeBLEU)
提出的方法
- 使用 BM25 算法选择少样本示例,构建输入提示,以提升零样本泛化能力。
- 在提示中引入角色模式,以模拟审查者角色,测试其对输出质量的影响。
- 在训练数据的小规模、随机采样子集上对 GPT-3.5 进行微调,使其适应代码审查任务。
- 使用两个标准指标(精确匹配 EM 和 CodeBLEU)在三个公开代码审查数据集(Tufano、D-ACT 和 CodeReviewer)上评估模型性能。
- 将零样本、少样本和微调后的 GPT-3.5 性能与现有的基于深度学习的代码审查自动化系统进行比较。
- 在所有实验中保持一致的提示模板与超参数设置,以确保可比性,遵循 OpenAI 的提示设计指南。

实验结果
研究问题
- RQ1RQ1:与零样本推理相比,少样本学习对 GPT-3.5 在代码审查自动化中的影响如何?
- RQ2RQ2:在输入提示中包含角色模式如何影响 GPT-3.5 生成改进代码的性能?
- RQ3RQ3:模型微调如何影响 GPT-3.5 相较于零样本和少样本设置的性能?
- RQ4RQ4:在代码质量指标方面,微调后的 GPT-3.5 与现有代码审查自动化方法相比表现如何?
主要发现
- 与零样本推理相比,少样本学习使 GPT-3.5 的精确匹配至少提升 46.38%,CodeBLEU 至少提升 3.97%。
- 与无角色模式的提示相比,在提示中加入角色模式使精确匹配至少降低 1.02%,CodeBLEU 至少降低 0.15%。
- 微调后的 GPT-3.5 在精确匹配上至少比零样本和少样本设置高出 9.74%,在 CodeBLEU 上高出至少 0.12%。
- 在所有数据集上,微调后的 GPT-3.5 在精确匹配上相比现有代码审查自动化方法至少提升 11.48%。
- 在所有三个数据集中,微调后的 GPT-3.5 均持续取得最高性能,尤其在修改令牌数量较多时表现更优。
- 在无注释的 Tufano 数据集中,少样本学习表现略优于微调,但微调后的 GPT-3.5 整体仍更优。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。