paperbot · PL 论文追踪

全部论文 待读 收藏

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

大语言模型是少样本摘要器:基于上下文学习的多意图注释生成
ICSE Proceedings of the IEEE/ACM 46th International Conference on Software Engineering2024匹配度 2/10 · 该论文属于“LLM 用于代码注释生成”的软件工程任务,既不涉及静态分析/形式化验证,也与浮点程序分析、贝叶斯程序分析及其与 LLM 的交叉无关;其核心是上下文学习提示构造与重排序等提示词层面的技巧,恰好落在用户不感兴趣的方向上。引用 139 inbox
Mingyang Geng, Shangwen Wang, Dezun Dong, Haotian Wang, Ge Li, Zhi Jin, Xiaoguang Mao, Xiangke Liao
crossref: 2026-09-12

AI 速览

一句话:实证表明大语言模型通过上下文学习即可生成满足多种开发者意图的代码注释,并显著超越有监督方法。

代码注释生成旨在为代码片段生成自然语言描述以辅助程序理解,但现有方法通常只能生成单一注释,难以满足开发者对功能、用法等多角度信息的需求。本文实证研究利用大语言模型(LLM)生成多意图注释的可行性,其直觉是 LLM 预训练中已建立代码与注释的语义关联,且真实注释包含多样开发者意图。作者采用上下文学习范式,通过设计充足提示(如提供十多个示例)与定制化提示构造及结果重排序策略,在两个大规模数据集上评估。结果显示,LLM 在多意图注释生成上显著优于最先进的有监督学习方法,且提示构造与后处理重排序均能进一步提升性能,为后续研究提供了方向。

问题
现有代码注释生成方法通常只能为一个代码片段生成单一意图的注释,无法满足开发者从功能、用法等多视角理解代码的需求。
方法
该研究采用上下文学习,通过为 LLM 设计包含若干示例的提示生成多意图注释,并探索定制化提示构造与结果重排序策略。
评估
在两个大规模代码数据集上实验,与最先进的有监督学习方法对比,并分析提示示例数量、提示构造和重排序策略的影响。
原文摘要(Abstract)

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.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot11466,
  title = {Large Language Models are Few-Shot Summarizers: Multi-Intent Comment Generation via In-Context Learning},
  author = {Mingyang Geng and Shangwen Wang and Dezun Dong and Haotian Wang and Ge Li and Zhi Jin and Xiaoguang Mao and Xiangke Liao},
  booktitle = {ICSE},
  year = {2024},
  doi = {10.1145/3597503.3608134}
}