Retrieve and Refine: Exemplar-based Neural Comment Generation
Not on the map. Why?
Abstract (arXiv)
Code comment generation which aims to automatically generate natural language descriptions for source code, is a crucial task in the field of automatic software development. Traditional comment generation methods use manually-crafted templates or information retrieval (IR) techniques to generate summaries for source code. In recent years, neural network-based methods which leveraged acclaimed encoder-decoder deep learning framework to learn comment generation patterns from a large-scale parallel code corpus, have achieved impressive results. However, these emerging methods only take code-related information as input. Software reuse is common in the process of software development, meaning that comments of similar code snippets are helpful for comment generation. Inspired by the IR-based and template-based approaches, in this paper, we propose a neural comment generation approach where we use the existing comments of similar code snippets as exemplars to guide comment generation. Specifically, given a piece of code, we first use an IR technique to retrieve a similar code snippet and treat its comment as an exemplar. Then we design a novel seq2seq neural network that takes the given code, its AST, its similar code, and its exemplar as input, and leverages the information from the exemplar to assist in the target comment generation based on the semantic similarity between the source code and the similar code. We evaluate our approach on a large-scale Java corpus, which contains about 2M samples, and experimental results demonstrate that our model outperforms the state-of-the-art methods by a substantial margin.
Key facts. Cited by 10 papers in the map (data through 7 Oct 2026). First posted on arXiv 9 Oct 2020.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2022: 5; 2023: 2; 2024: 2; 2025: 1.
10 papers.
- 2024Retrieval-Augmented Generation for AI-Generated Content: A Surveycited by 352
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkitcited by 22
- 2022M2TS: Multi-Scale Multi-Modal Approach Based on Transformer for Source Code Summarizationcited by 14
- 2022BashExplainer: Retrieval-Augmented Bash Code Comment Generation based on Fine-tuned CodeBERTcited by 9
- 2022GypSum: Learning Hybrid Representations for Code Summarizationcited by 5
- 2024Improving Retrieval-Augmented Code Comment Generation by Retrieving for Generationcited by 4
- 2022Automatic Comment Generation via Multi-Pass Deliberationcited by 3
- 2023Revisiting File Context for Source Code Summarizationcited by 3
- 2022LAMNER: Code Comment Generation Using Character Language Model and Named Entity Recognitioncited by 1
- 2025Issue Retrieval and Verification Enhanced Supplementary Code Comment Generationcited by 0
- 2025Issue Retrieval and Verification Enhanced Supplementary Code Comment Generation17 Jun 2025
- 2024Improving Retrieval-Augmented Code Comment Generation by Retrieving for Generation7 Aug 2024
- 2024Retrieval-Augmented Generation for AI-Generated Content: A Survey29 Feb 2024
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkit30 Dec 2023
- 2023Revisiting File Context for Source Code Summarization5 Sep 2023
- 2022Automatic Comment Generation via Multi-Pass Deliberation14 Sep 2022
- 2022BashExplainer: Retrieval-Augmented Bash Code Comment Generation based on Fine-tuned CodeBERT27 Jun 2022
- 2022GypSum: Learning Hybrid Representations for Code Summarization26 Apr 2022
- 2022LAMNER: Code Comment Generation Using Character Language Model and Named Entity Recognition5 Apr 2022
- 2022M2TS: Multi-Scale Multi-Modal Approach Based on Transformer for Source Code Summarization18 Mar 2022