arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2304.11384cs.SE
收藏

大语言模型是少样本摘要生成器:基于上下文学习的多意图注释生成

Large Language Models are Few-Shot Summarizers: Multi-Intent Comment Generation via In-Context Learning

Mingyang Geng, Shangwen Wang, Dezun Dong, Haotian Wang, Ge Li, Zhi Jin, Xiaoguang Mao, Xiangke Liao

AI总结:

本研究针对现有代码注释生成方法仅能生成单条注释、无法满足开发者多样信息需求的问题,实证验证了采用上下文学习范式的大语言模型可生成多意图注释,且提示构建与后处理策略能进一步提升性能。

摘要:

代码注释生成旨在为代码片段生成自然语言描述,以辅助开发者的程序理解工作。尽管该领域已被研究良久,现有方法的一个瓶颈在于:给定一个代码片段,它们只能生成一条注释,但开发者通常需要了解多维度的信息,比如该代码片段的功能是什么、如何使用它。\n为解决这一局限,本研究实证探究了利用大语言模型(LLMs)生成可满足开发者多样意图的注释的可行性。我们的思路基于两点事实:(1)LLMs的预训练过程会使用代码及其配对注释,以构建自然语言与编程语言之间的语义关联;(2)用于预训练的、从真实项目中收集的注释,通常包含不同开发者的意图。因此我们假设,LLMs在预训练后已经能够从不同视角理解代码。\n实际上,在两个大规模数据集上的实验证明了我们观点的合理性:采用上下文学习范式并为LLM提供充分的提示(例如,为其提供10个或更多示例),LLM在生成多意图注释方面的表现可显著优于当前最优的监督学习方法。结果还表明,用于构建提示的定制化策略、以及用于对结果重排序的后处理策略,都能提升LLM的性能,这为未来使用LLMs实现注释生成的研究方向提供了思路。

英文摘要:

Code comment generation aims at generating natural language descriptions for a code snippet to facilitate developers' program comprehension activities. Despite being studied for a long time, a bottleneck for existing approaches is that given a code snippet, they can only generate one comment while developers usually need to know information from diverse perspectives such as what is the functionality of this code snippet and how to use it. To tackle this limitation, this study empirically investigates the feasibility of utilizing large language models (LLMs) to generate comments that can fulfill developers' diverse intents. Our intuition is based on the facts that (1) the code and its pairwise comment are used during the pre-training process of LLMs to build the semantic connection between the natural language and programming language, and (2) comments in the real-world projects, which are collected for the pre-training, usually contain different developers' intents. We thus postulate that the LLMs can already understand the code from different perspectives after the pre-training. Indeed, experiments on two large-scale datasets demonstrate the rationale of our insights: by adopting the in-context learning paradigm and giving adequate prompts to the LLM (e.g., providing it with ten or more examples), the LLM can significantly outperform a state-of-the-art supervised learning approach on generating comments with multiple intents. Results also show that customized strategies for constructing the prompts and post-processing strategies for reranking the results can both boost the LLM's performances, which shed light on future research directions for using LLMs to achieve comment generation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑