[论文解读] Source Code Summarization in the Era of Large Language Models
本文对基于大语言模型(LLM)的源代码摘要生成进行了全面的实证研究,评估了提示工程技巧、模型超参数以及不同编程语言下LLM的能力。研究发现,基于GPT-4的评估最符合人类判断,零样本提示通常优于高级技术,且出人意料的是,7B参数的CodeLlama-Instruct在生成语义和属性聚焦的代码摘要方面超越了GPT-4。
To support software developers in understanding and maintaining programs, various automatic (source) code summarization techniques have been proposed to generate a concise natural language summary (i.e., comment) for a given code snippet. Recently, the emergence of large language models (LLMs) has led to a great boost in the performance of code-related tasks. In this paper, we undertake a systematic and comprehensive study on code summarization in the era of LLMs, which covers multiple aspects involved in the workflow of LLM-based code summarization. Specifically, we begin by examining prevalent automated evaluation methods for assessing the quality of summaries generated by LLMs and find that the results of the GPT-4 evaluation method are most closely aligned with human evaluation. Then, we explore the effectiveness of five prompting techniques (zero-shot, few-shot, chain-of-thought, critique, and expert) in adapting LLMs to code summarization tasks. Contrary to expectations, advanced prompting techniques may not outperform simple zero-shot prompting. Next, we investigate the impact of LLMs' model settings (including top\_p and temperature parameters) on the quality of generated summaries. We find the impact of the two parameters on summary quality varies by the base LLM and programming language, but their impacts are similar. Moreover, we canvass LLMs' abilities to summarize code snippets in distinct types of programming languages. The results reveal that LLMs perform suboptimally when summarizing code written in logic programming languages compared to other language types. Finally, we unexpectedly find that CodeLlama-Instruct with 7B parameters can outperform advanced GPT-4 in generating summaries describing code implementation details and asserting code properties. We hope that our findings can provide a comprehensive understanding of code summarization in the era of LLMs.
研究动机与目标
- 系统评估基于大语言模型的代码摘要生成在不同提示工程技巧、模型设置和编程语言下的有效性。
- 识别最可靠的自动化评估方法,用于评估LLM生成的代码摘要,尤其是当其与参考摘要存在差异时。
- 调查高级提示工程技巧是否始终优于简单的零样本提示,从而提升代码摘要质量。
- 评估模型超参数(top_p,temperature)对不同LLM和编程语言下摘要质量的影响。
- 评估不同LLM在总结各类编程语言代码(包括逻辑编程)方面的表现。
提出的方法
- 本研究使用涵盖多种编程语言的多样化代码片段数据集,评估了四种LLM(CodeLlama-Instruct、StarChat-β、GPT-3.5和GPT-4)在代码摘要任务中的表现。
- 比较了五种提示工程技巧:零样本、 few-shot、思维链(chain-of-thought)、批判性提示(critique)和专家提示(expert prompting),以评估其对摘要质量的影响。
- 系统性地调整模型超参数(top_p 和 temperature),分析其对摘要质量的影响,评估中将 temperature 设为 0.1 或 0 以确保确定性。
- 采用启发式规则-based 方法从LLM生成的响应中提取简洁的代码注释,随后使用多种自动化指标进行评估。
- 本研究使用GPT-4作为类人评估者来评估摘要质量,并将其结果与BLEU、METEOR、ROUGE-L和语义相似性度量等传统指标进行对比。
- 在多种编程语言上开展消融研究,以确保研究发现具有泛化能力,而非受特定语言特征的偏差影响。
实验结果
研究问题
- RQ1哪种自动化评估方法最接近人类判断,用于评估LLM生成的代码摘要质量?
- RQ2与零样本提示相比,高级提示工程技巧(如思维链、批判性提示)是否始终能提升代码摘要性能?
- RQ3top_p 和 temperature 等模型超参数如何影响不同基础LLM和编程语言下LLM生成的摘要质量?
- RQ4LLM在总结不同类型的编程语言代码(尤其是逻辑编程,LP)时表现如何?
- RQ5较小的开源LLM(如CodeLlama-Instruct)是否能在生成特定类型代码摘要方面超越更大的专有模型(如GPT-4)?
主要发现
- 基于GPT-4的评估方法最符合人类判断,在评估摘要质量方面优于BLEU、METEOR和ROUGE-L等传统指标。
- 高级提示工程技巧(如思维链和批判性提示)并未始终优于简单的零样本提示,后者往往产生更优结果。
- top_p 和 temperature 对摘要质量的影响在不同LLM和编程语言间相似,尽管影响程度因基础模型和语言而异。
- LLM在总结逻辑编程(LP)代码时表现欠佳,其摘要质量显著低于过程式和面向对象语言。
- 7B参数的CodeLlama-Instruct在生成“为何”类摘要(4.29 vs. 4.28)和“属性”类摘要(4.19 vs. 4.06)方面优于GPT-4,表明其在捕捉语义和形式属性方面具有强大能力。
- 本研究证明,开源且参数较小的LLM可在特定摘要任务中实现与大型商业模型相当甚至更优的性能,尤其在语义和属性聚焦的摘要生成方面。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。