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

CoreGen: Contextualized Code Representation Learning for Commit Message Generation

Lun Yiu Nie, Cuiyun Gao, Zhicong Zhong, Wai Lam, Yang Liu, Zenglin Xu

Abstract

Writing high-quality commit messages is essential for software maintenance, yet it remains a task frequently neglected by developers. Traditional Neural Machine Translation (NMT) approaches often fail due to the "semantic gap" between source code and natural language, largely caused by the use of static embeddings that ignore programming context. We introduce CoreGen, a two-stage Transformer-based framework designed to bridge this gap through contextualized code representation learning. By pre-training on specialized tasks—predicting code changes and filling masked fragments—CoreGen significantly outperforms previous state-of-the-art models, achieving a 28.18% improvement in BLEU-4 scores.

Introduction

The primary challenge in automated commit message generation is the semantic gap. Most existing models treat code tokens as static text, using embeddings where a token like list has the same representation regardless of its functional role. Furthermore, these models often fail to distinguish between explicit code changes (line-level diffs) and implicit changes (such as binary file updates). CoreGen addresses these issues by learning representations that adapt based on surrounding code context and the specific nature of the commit.

Methodology: The CoreGen Framework

CoreGen utilizes a two-stage approach built upon the Transformer architecture to move beyond static embeddings and capture the nuances of code evolution.

Overview of the CoreGen two-stage framework, illustrating the transition from representation learning to message generation.

Stage I: Contextualized Code Representation Learning

In the first stage, the model undergoes self-supervised pre-training on two distinct tasks designed to capture the logic of code changes:

  1. Code Changes Prediction (Explicit Changes): The model predicts the "after" state of a code snippet given its "before" state, forcing the encoder to focus on logical deltas.
  2. Masked Code Fragment Prediction (Implicit Changes): Similar to masked language modeling in NLP, the model predicts a hidden code fragment based on the surrounding context, which is particularly effective for understanding non-textual or implicit updates.
Detailed architecture of CoreGen's Transformer blocks and the specific pre-training tasks for explicit and implicit changes.

Stage II: Downstream Commit Message Generation

The weights and representations learned in Stage I are transferred to Stage II. Here, the model is fine-tuned on a labeled dataset to generate natural language summaries (commit messages) for specific code changes.

Experimental Setup

The study utilizes a refined benchmark dataset of approximately 27,000 pairs of code commits and messages, derived from a larger 2-million-pair corpus. This "cleansed" dataset filters out noise and non-informative tokens to ensure high-quality training. The data is split into training, validation, and test sets using an 8:1:1 ratio.

Results and Discussion

CoreGen establishes a new state-of-the-art performance across multiple evaluation metrics:

  • BLEU-4 Score: CoreGen achieved a score of 21.06, representing a 28.18% improvement over the previous best-performing retrieval-based model (NNGen).
  • ROUGE & METEOR: Significant gains were observed (e.g., ROUGE-L increased from 24.46 to 30.85), indicating that the generated messages are structurally and semantically closer to human-written summaries.
  • Efficiency: Pre-training in Stage I allows the model to converge 25 epochs earlier than a standard Transformer.
  • Robustness: CoreGen maintains superior performance even in low-resource scenarios, outperforming existing models with only 50% of the training data.

Conclusion and Future Work

CoreGen demonstrates that contextualized representation learning is a powerful tool for bridging the semantic gap in code-to-text tasks. Future research will explore incorporating structural information, such as Control Flow Graphs (CFG) and Program Dependency Graphs (PDG), to further deepen the model's understanding of program logic. Additionally, scaling the framework to massive, multi-language corpora could enhance its generalizability across diverse programming environments.

Summary updated

BibTeX
@article{nie2021coregen,
  author = {Lun Yiu Nie and Cuiyun Gao and Zhicong Zhong and Wai Lam and Yang Liu and Zenglin Xu},
  title = {{CoreGen: Contextualized Code Representation Learning for Commit Message Generation}},
  journal = {Neurocomputing},
  year = {2021},
  doi = {10.1016/j.neucom.2021.05.039},
}
Figure