当检索器遇见生成器:一种用于代码注释生成的联合模型
When Retriever Meets Generator: A Joint Model for Code Comment Generation
AI总结:
本文提出 RAGSum,基于单一 CodeT5 主干联合优化代码注释的检索与生成,并通过对比预训练、复合损失和自精炼循环,在 Java、Python、C 基准上显著提升注释质量。
摘要:
为源代码自动生成简洁且信息丰富的注释,可以减轻文档编写工作并加快程序理解。检索增强方法首先获取带有现有注释的代码片段,然后合成新的注释;然而,检索和生成通常是孤立优化的,这会使不相关的近邻将噪声传播到下游。为解决该问题,我们提出了一种名为 RAGSum 的新颖方法,旨在兼顾推荐的有效性和效率。RAGSum 构建于融合检索与生成之上,使用单一 CodeT5 主干网络。我们报告了在基于 CodeT5 构建的统一检索—生成框架上的初步结果。对比预训练阶段塑造用于最近邻搜索的代码嵌入;这些权重随后作为端到端训练的初始值,训练采用复合损失,该损失:(i)奖励准确的 top-k 检索;并且(ii)最小化注释生成误差。更重要的是,部署了一个轻量级自精炼循环来润色最终输出。我们在三个跨语言基准(Java、Python、C)上评估了该框架,并将其与三个成熟基线进行比较。结果表明,我们的方法在 BLEU、METEOR 和 ROUTE-L 方面显著优于这些基线。这些发现表明,紧密耦合检索和生成可以提高注释自动化的上限,并推动后续复现以及面向开发者的定性研究。
英文摘要:
Automatically generating concise, informative comments for source code can lighten documentation effort and accelerate program comprehension. Retrieval-augmented approaches first fetch code snippets with existing comments and then synthesize a new comment, yet retrieval and generation are typically optimized in isolation, allowing irrelevant neighbors topropagate noise downstream. To tackle the issue, we propose a novel approach named RAGSum with the aim of both effectiveness and efficiency in recommendations. RAGSum is built on top offuse retrieval and generation using a single CodeT5 backbone. We report preliminary results on a unified retrieval-generation framework built on CodeT5. A contrastive pre-training phase shapes code embeddings for nearest-neighbor search; these weights then seed end-to-end training with a composite loss that (i) rewards accurate top-k retrieval; and (ii) minimizes comment-generation error. More importantly, a lightweight self-refinement loop is deployed to polish the final output. We evaluated theframework on three cross-language benchmarks (Java, Python, C), and compared it with three well-established baselines. The results show that our approach substantially outperforms thebaselines with respect to BLEU, METEOR, and ROUTE-L. These findings indicate that tightly coupling retrieval and generationcan raise the ceiling for comment automation and motivateforthcoming replications and qualitative developer studies.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。