Skip to main content
QUICK REVIEW

[论文解读] Large Language Models are Few-Shot Summarizers: Multi-Intent Comment Generation via In-Context Learning

Mingyang Geng, Shangwen Wang|arXiv (Cornell University)|Apr 22, 2023
Software Engineering ResearchComputer Science被引用 9
一句话总结

论文表明大型语言模型(Codex)能够通过上下文学习生成具有多种意图的代码注释,在使用十个示例和基于检索的示例策略再加上再排序时 gains 显著提升。

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.

研究动机与目标

  • 将多意图代码注释生成动机化,以反映超越一对一映射的多样开发者意图。
  • 探究带有上下文学习的预训练大语言模型是否在无需微调的情况下即可从多种视角生成注释。
  • 评估示例数量、基于检索的示例选择以及事后再排序以最大化性能。
  • 与最先进的监督方法(DOME)在大型 Java 代码-注释数据集 Funcom 与 TLC 上进行对比。

提出的方法

  • 使用 OpenAI Codex 作为 LLM 进行多意图代码注释生成的上下文学习。
  • 提供一个提示模板,包含语言指令、意图类别,以及一组具有对应注释的代码示例。
  • 设计两种检索策略(基于符号的和基于语义的)以选择与目标代码相似的示例用于提示构建。
  • 对生成的注释应用一个再排序策略,使用与最相似检索代码的参考注释并计算基于 token 的相似度与语义相似度。
  • 在 Funcom 与 TLC Java 数据集上使用 BLEU、ROUGE-L 和 METEOR 作为评估指标。
  • 进行多次(100 次)运行以应对零-shot/一-shot 情况下的随机性并报告平均值;对再排序评估同样进行 100 次以估计最优结果。
Figure 1 . Multi-intent code summarization prompt template.
Figure 1 . Multi-intent code summarization prompt template.

实验结果

研究问题

  • RQ1RQ1:在零-shot、 一-shot 和少量-shot 的条件下,Codex 在多意图注释生成方面对比 DOME 的效果如何?
  • RQ2RQ2:基于检索的示例选择是否能提升 Codex 的性能?
  • RQ3RQ3:对生成的注释进行再排序是否能进一步提升 Codex 的结果?

主要发现

  • Codex 在示例越多时越有提升;10-shot 提示在 BLEU、ROUGE-L、METEOR 上的平均表现优于 DOME。
  • 通过与目标代码相似性的示例选择能显著提升性能(Funcom 与 TLC 的 BLEU 分别相比随机选择提高 97% 和 131%)。
  • 使用与相似代码的参考注释进行再排序可带来额外提升(Funcom 与 TLC 的 BLEU 最高约提升 ~9.9% 和 ~9.6%)。
  • 零-shot 与一-shot 的 Codex 表现落后于 DOME,但 5-shot 的 Codex 在 ROUGE-L 与 METEOR 上具有竞争力,且 10-shot 在两个数据集的所有指标上始终超过 DOME。
  • 在不同意图下,使用 10-shot 提示的 Codex 最佳结果相较零/少-shot 基线有显著提升,显示了大语言模型在多意图代码注释生成中的潜力。
  • 这些发现对基于提示设计、示例检索和后处理在 LLM 驱动的代码注释生成中提供了有前景的方向。
Figure 2 . Overview of our in-context learning-based code summarization.
Figure 2 . Overview of our in-context learning-based code summarization.

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。