NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

RACE: Retrieval-augmented Commit Message Generation

Ensheng Shi, Yanlin Wang, Wei Tao, Lun Du, Hongyu Zhang, Shi Han, Dongmei Zhang, Hongbin Sun

Abstract

Automating commit message generation is crucial for maintaining software quality, yet existing methods often struggle with either generic outputs or contextually irrelevant suggestions. This paper introduces RACE (Retrieval-Augmented Commit mEssage generation), a framework that enhances neural models by retrieving similar code changes (exemplars) and using them to guide the generation process. A core innovation, the "exemplar guider," dynamically weights the influence of retrieved content based on semantic similarity. Experimental results across five programming languages demonstrate that RACE significantly outperforms state-of-the-art baselines, providing more informative and context-aware commit messages.

Introduction

High-quality commit messages are vital for understanding software evolution and facilitating maintenance. However, developers frequently provide brief or uninformative messages due to the manual effort required. Previous automation attempts fall into two categories: Information Retrieval (IR) and Neural Machine Translation (NMT). IR-based methods often "copy-paste" messages that may not fit the current context, while NMT-based models tend to generate "safe" but generic phrases like "update readme.md."

RACE addresses these limitations by combining the strengths of both approaches. It uses retrieval to provide a rich "exemplar" while employing a neural model to ensure the final message is precisely tailored to the specific code diff.

Methodology: The RACE Framework

The RACE framework consists of two primary components: a Retrieval Module and a Generation Module.

1. Retrieval Module

The system utilizes a trained "code diff encoder" to map code changes into a high-dimensional semantic space. For any new input code diff, the module searches a large training corpus to find the most semantically similar diff and its associated commit message. Unlike traditional lexical matching (e.g., TF-IDF), this semantic approach better captures the developer's intent.

2. Generation Module and Exemplar Guider

The generation module employs three Transformer-based encoders (for the input diff, the retrieved diff, and the retrieved message) and a Transformer decoder. The "magic" lies in the Exemplar Guider, which calculates a similarity score ($\lambda$) between the current diff and the retrieved exemplar.

The RACE framework architecture, featuring Retrieval and Generation modules.

If the retrieved diff is a close match, $\lambda$ is high, and the model relies heavily on the exemplar. If the match is poor, the model prioritizes its internal understanding of the input diff. This "safety valve" prevents the model from being forced to use irrelevant information.

Experimental Setup

RACE was evaluated using the Multi-language Commit Message Dataset (MCMD), which includes approximately 0.9 million pairs across Java, C#, C++, Python, and JavaScript. To improve precision, the researchers used token-level change actions (e.g., <insert>, <delete>) rather than standard line-level diffs.

Results and Discussion

RACE demonstrated superior performance across all evaluated languages and metrics. It effectively "boosts" existing models; for instance, it improved the BLEU score of NMTGen by 43% and CodeT5-base by 16%.

Performance comparison of RACE against state-of-the-art baselines across five programming languages.

Key Insights

  • Plug-and-Play Versatility: RACE is a flexible framework that can enhance various base models (like CommitBERT or CodeT5) by wrapping them in retrieval-augmentation logic.
  • Avoiding Genericity: Human evaluations confirmed that RACE produces more informative, concise, and expressive messages than baselines, successfully avoiding the "generic message" trap common in NMT models.

Conclusion and Future Work

While RACE sets a new state-of-the-art, it faces challenges such as high computational training costs (approx. 35 hours on 4x V100 GPUs) and the "cold start" problem inherent in retrieval-based systems. Future work will focus on handling "long diffs" that exceed current token limits and extending the framework to a wider variety of programming environments.

Summary updated

BibTeX
@inproceedings{shi2022race,
  author = {Ensheng Shi and Yanlin Wang and Wei Tao and Lun Du and Hongyu Zhang and Shi Han and Dongmei Zhang and Hongbin Sun},
  title = {{RACE: Retrieval-augmented Commit Message Generation}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.372},
}
Figure