Improving Retrieval-Augmented Code Comment Generation by Retrieving for Generation
On the map: Retrieval-augmented generation → RAG for code
Abstract (arXiv)
Code comment generation aims to generate high-quality comments from source code automatically and has been studied for years. Recent studies proposed to integrate information retrieval techniques with neural generation models to tackle this problem, i.e., Retrieval-Augmented Comment Generation (RACG) approaches, and achieved state-of-the-art results. However, the retrievers in previous work are built independently of their generators. This results in that the retrieved exemplars are not necessarily the most useful ones for generating comments, limiting the performance of existing approaches. To address this limitation, we propose a novel training strategy to enable the retriever to learn from the feedback of the generator and retrieve exemplars for generation. Specifically, during training, we use the retriever to retrieve the top-k exemplars and calculate their retrieval scores, and use the generator to calculate a generation loss for the sample based on each exemplar. By aligning high-score exemplars retrieved by the retriever with low-loss exemplars observed by the generator, the retriever can learn to retrieve exemplars that can best improve the quality of the generated comments. Based on this strategy, we propose a novel RACG approach named JOINTCOM and evaluate it on two real-world datasets, JCSD and PCSD. The experimental results demonstrate that our approach surpasses the state-of-the-art baselines by 7.3% to 30.0% in terms of five metrics on the two datasets. We also conduct a human evaluation to compare JOINTCOM with the best-performing baselines. The results indicate that JOINTCOM outperforms the baselines, producing comments that are more natural, informative, and useful.
Key facts. Cited by 4 papers in the map (data through 7 Oct 2026). Placed in RAG for code, one of 15 directions in Retrieval-augmented generation. Builds on 24 of its 67 references that are in the map. First posted on arXiv 7 Aug 2024.
Builds on
24 of 67 references.
References · 24
- 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
- 2019BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehensioncited by 5,874
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2014CIDEr: Consensus-based Image Description Evaluationcited by 2,027
- 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 890
- 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 732
- 2022UniXcoder: Unified Cross-Modal Pre-training for Code Representationcited by 355
- 2023CodeT5+: Open Code Large Language Models for Code Understanding and Generationcited by 327
- 2017Learning to Represent Programs with Graphscited by 219
- 2016Sequence-to-Sequence Learning as Beam-Search Optimizationcited by 126
12 more
- 2018Improving Automatic Source Code Summarization via Deep Reinforcement Learningcited by 99
- 2018Guiding Neural Machine Translation with Retrieved Translation Piecescited by 63
- 2017A parallel corpus of Python functions and documentation strings for automated code documentation and code generationcited by 56
- 2022CoditT5: Pretraining for Source Code and Natural Language Editingcited by 45
- 2016Incorporating Discrete Translation Lexicons into Neural Machine Translationcited by 33
- 2021Code Structure Guided Transformer for Source Code Summarizationcited by 29
- 2020Code to Comment "Translation": Data, Metrics, Baselining & Evaluationcited by 28
- 2023EditSum: A Retrieve-and-Edit Framework for Source Code Summarizationcited by 18
- 2023CCT5: A Code-Change-Oriented Pre-Trained Modelcited by 17
- 2021Ensemble Models for Neural Source Code Summarization of Subroutinescited by 12
- 2020Retrieve and Refine: Exemplar-based Neural Comment Generationcited by 10
- 2022Automatic Comment Generation via Multi-Pass Deliberationcited by 3
Built on by
Citing papers per year: 2025: 4.
4 papers.
- 2025Large Language Models (LLMs) for Source Code Analysis: applications, models and datasetscited by 15
- 2025Retrieval-Augmented Code Review Comment Generationcited by 6
- 2025Across Programming Language Silos: A Study on Cross-Lingual Retrieval-augmented Code Generationcited by 3
- 2025Issue Retrieval and Verification Enhanced Supplementary Code Comment Generationcited by 0
- 2025Issue Retrieval and Verification Enhanced Supplementary Code Comment Generation17 Jun 2025
- 2025Retrieval-Augmented Code Review Comment Generation13 Jun 2025
- 2025Across Programming Language Silos: A Study on Cross-Lingual Retrieval-augmented Code Generation4 Jun 2025
- 2025Large Language Models (LLMs) for Source Code Analysis: applications, models and datasets21 Mar 2025
Similar, not cited
Close in wording, no citation either way
- 2025When Retriever Meets Generator: A Joint Model for Code Comment Generation ↗
- 2025An Empirical Study of Retrieval-Augmented Code Generation: Challenges and Opportunities
- 2025When More Retrieval Hurts: Retrieval-Augmented Code Review Generation
- 2025Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approaches
- 2025SACL: Understanding and Combating Textual Bias in Code Retrieval with Semantic-Augmented Reranking and Localization
- 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?
- 2025What to Retrieve for Effective Retrieval-Augmented Code Generation? An Empirical Study and Beyond
- 2024Assessing the Answerability of Queries in Retrieval-Augmented Code Generation