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

A Sketch-Based Neural Model for Generating Commit Messages from Diffs

Nicolae-Teodor Pavel, Traian RebedeaarXiv 2021

Abstract

Automating the generation of descriptive commit messages from code changes (diffs) remains a significant challenge in software engineering due to the structural complexity of code and the prevalence of out-of-vocabulary identifiers. This paper presents a novel sketch-based neural model that abstracts Java source code into structural templates, or "sketches," to mitigate these issues. By combining deep Neural Machine Translation (NMT) architectures with residual connections and employing an ensemble of models specialized for various file types, the proposed method achieves state-of-the-art performance. Evaluation on large-scale datasets demonstrates that the sketch-based approach significantly outperforms existing retrieval-based and vanilla NMT baselines, particularly for complex logic changes in Java files.

Introduction

Informative commit messages are essential for maintaining a transparent and navigable project history. However, developers frequently neglect this task, leading to cryptic or unhelpful documentation. Automating message generation is difficult because code diffs differ fundamentally from natural language; they are highly structured and contain a vast, project-specific vocabulary. Previous attempts using standard NMT models often failed to surpass simple nearest-neighbor algorithms like NNGen. This paper addresses these challenges through structural abstraction and specialized model ensembles.

Methods

The proposed framework incorporates three primary innovations:

NMT Optimization

The researchers moved beyond shallow models, exploring deeper architectures (up to 8 layers) with residual connections to ensure stable gradient flow during training on long code sequences. Byte Pair Encoding (BPE) and copying mechanisms were integrated to handle rare tokens and user-defined variables that the model had not encountered during training.

File-Type Ensembles

Recognizing that different file formats (e.g., XML, Gradle, Java) follow distinct patterns, the researchers trained an ensemble of specialized models. This allows the system to capture the unique "grammar" of each file type more effectively than a single monolithic model, preventing trivial files from skewing the learning process for complex source code.

Sketch-Based Encoding

For Java source code, the model employs a "sketching" phase where identifiers (variables, functions, classes) are replaced with generic placeholders (e.g., var_0, fnc_1). The NMT model then learns to map the structural change to a message template. During inference, these placeholders are restored to their original values using a mapping dictionary created during the sketching phase.

Datasets

The study utilized two major benchmarks: the Jiang et al. dataset, containing 2 million commits from 1,000 Java repositories, and a cleaned version by Liu et al. that filters out trivial housekeeping commits. Analysis of these datasets reveals a diverse distribution of file types, with Java being the most frequent, followed by configuration and build files like XML and Gradle.

Distribution of file types in the original and cleaned datasets

Results and Key Insights

The sketch-based model achieved a BLEU-4 score of 13.64 for Java files, surpassing both NNGen (13.1) and vanilla NMT (9.7). On the full Jiang dataset, the ensemble model reached a BLEU-4 of 39.54.

A critical finding was the impact of model depth and architectural choices. Specifically, residual connections provided a massive boost in performance. As shown in the experimental results, adding residual connections to a 4-layer model increased the BLEU-4 score from 34.07 to 38.45.

Impact of model depth and residual connections on BLEU-4 scores

Human evaluation further validated these results, with 44% of generated messages rated as medium to high quality by professional developers. While the neural model is slower than nearest-neighbor approaches, its ability to generalize to new code structures represents a significant advancement.

Conclusion

This work highlights the importance of structural awareness in code-to-text tasks. By abstracting code into sketches and leveraging file-specific ensembles, the proposed model provides a more robust solution for automated commit message generation. Future research will focus on improving inference efficiency and incorporating broader architectural context via Abstract Syntax Trees (AST) to better capture the intent behind code changes.

Summary updated

BibTeX
@misc{pavel2021sketch,
  author = {Nicolae-Teodor Pavel and Traian Rebedea},
  title = {{A Sketch-Based Neural Model for Generating Commit Messages from Diffs}},
  year = {2021},
  eprint = {2104.04087},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2104.04087},
}
Figure