| 本文已被:浏览 1296次 下载 1811次 |
 码上扫一扫! |
|
|
| 基于Issue检索增强大语言模型的补充性代码注释生成 |
|
潘兴禄1,2, 赵衔麟1,2, 刘陈晓1,2, 邹艳珍1,2, 谢冰1,2
|
|
1.高可信软件技术教育部重点实验室 (北京大学), 北京 100871;2.北京大学 计算机学院, 北京 100871
|
|
| 摘要: |
| 随着编程命名规范的普及和自描述代码的深入实践, 传统与代码字面相似的摘要性代码注释逐渐失去开发者的青睐. 开发者更关注在理解和维护代码过程中能够提供额外信息的补充性代码注释. 但是, 补充性代码注释的生成往往需要代码之外的额外信息源, 且注释中呈现的补充内容复杂多样, 给现有工作带来很大的挑战. 将软件开发中开发者之间的Issue交流记录作为额外信息源, 提出一种基于Issue检索增强大语言模型的补充性代码注释生成方法. 该方法首先将Issue中的代码补充信息整理分类为5种类型, 再利用大语言模型从代码提交时所关联的Issue中检索出包含潜在类型补充信息的语句, 随后根据相应语句进行注释生成. 进一步, 该方法通过分析生成注释的代码相关性和Issue可验证性, 能较好地过滤生成注释中潜在的幻觉. 在两个主流大语言模型ChatGPT和GPT-4o上进行了实验. 实验结果表明, 所提方法能够将ChatGPT生成注释对于人工补充性注释的覆盖率从33.6%提升至72.2%, 将GPT-4o生成注释对于人工补充性注释的覆盖率从35.8%提升至88.4%, 显著地提升了补充性代码注释的生成效果. 同时, 所提方法所生成的注释相比现有方法能够明显提供更多对开发者有帮助的额外信息, 从而对开发者在理解一些复杂代码时具有十分重要的价值. |
| 关键词: 代码注释 注释生成 补充性代码注释 Issue 大语言模型 |
| DOI:10.13328/j.cnki.jos.007369 |
| 分类号:TP311 |
| 基金项目:国家重点研发计划(2023YFB4503803) |
|
| Issue-based LLM Retrieval Augmentation for Generating Supplementary Code Comments |
|
PAN Xing-Lu1,2, ZHAO Xian-Lin1,2, LIU Chen-Xiao1,2, ZOU Yan-Zhen1,2, XIE Bing1,2
|
|
1.Key Lab of High Confidence Software Technologies (Peking University), Ministry of Education, Beijing 100871, China;2.School of Computer Science, Peking University, Beijing 100871, China
|
| Abstract: |
| With the widespread adoption of programming naming conventions and the increasing emphasis on self-explanatory code, traditional summarizing code comments, which are often similar to code literal meaning, are losing appeal among developers. Instead, developers value supplementary code comments that provide additional information beyond the code itself to facilitate program understanding and maintenance. However, generating such comments typically requires external information resources beyond the code base, and the diversity of supplementary information presents significant challenges to existing methods. This study leverages Issue reports as a crucial external information source and proposes an Issue-based retrieval augmentation method using large language models (LLMs) to generate supplementary code comments. The proposed method classifies the supplementary information found in Issue reports into five categories, retrieves Issue sentences containing this information, and generates corresponding comments using LLMs. In addition, the code relevance and Issue verifiability of the generated comments are evaluated to minimize hallucinations. Experiments conducted on two popular LLMs, ChatGPT and GPT-4o, demonstrate the effectiveness of the proposed method. Compared to existing approaches, the proposed method significantly improves the coverage of manual supplementary comments from 33.6% to 72.2% for ChatGPT and from 35.8% to 88.4% for GPT-4o. Moreover, the generated comments offer developers valuable supplementary information, proving essential for understanding some tricky code. |
| Key words: code comment comment generation supplementary code comment Issue large language model (LLM) |