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

Learning to Represent Patches

Xunzhu Tang, Haoye Tian, Zhenghan Chen, Weiguo Pian, Saad Ezzini, Abdoul Kader Kaboré, Andrew Habib, Jacques Klein, Tegawendé F. BissyandéICSE Companion 2023

Abstract

Patch representation is crucial in automating various software engineering tasks, like determining patch accuracy or summarizing code changes. While recent research has employed deep learning for patch representation, focusing on token sequences or Abstract Syntax Trees (ASTs), they often miss the change's semantic intent and the context of modified lines. To bridge this gap, we introduce a novel method, Patcherizer. It delves into the intentions of context and structure, merging the surrounding code context with two innovative representations. These capture the intention in code changes and the intention in AST structural modifications pre and post-patch. This holistic representation aptly captures a patch's underlying intentions. Patcherizer employs graph convolutional neural networks for structural intention graph representation and transformers for intention sequence representation. We evaluated Patcherizer's embeddings' versatility in three areas: (1) Patch description generation, (2) Patch accuracy prediction, and (3) Patch intention identification. Our experiments demonstrate the representation's efficacy across all tasks, outperforming state-of-the-art methods. For example, in patch description generation, Patcherizer excels, showing an average boost of 19.39% in BLEU, 8.71% in ROUGE-L, and 34.03% in METEOR scores.

The Challenge of Patch Representation

In software engineering, a "patch"—the difference between two versions of code—is more than just a text diff; it represents a logical change or a "fix." Automating tasks like writing commit messages or verifying if a bug fix is actually correct requires machine learning models to represent these patches effectively.

Existing approaches often fall into two traps. Sequence-only models treat code like natural language text, missing the rich structural logic of programming. Conversely, structure-only models focus on Abstract Syntax Trees (ASTs) but often ignore the surrounding context or fail to explicitly calculate the semantic shift (the "intention") between the "before" and "after" states. To truly represent a patch, a model must capture the intention—how the code's logic and structure changed—while keeping the surrounding context in view.

The Patcherizer Framework

Patcherizer is a novel representation learning framework that "understands" software patches by explicitly modeling the developer's intention. It employs a multi-modal architecture to fuse three types of information: contextual code, sequence-based intention, and structural intention.

Overview of the Patcherizer framework, illustrating the preprocessing, embedding, and task layers.

The architecture consists of three primary components:

  1. Contextual Information: The code surrounding the change, providing the necessary semantic background.
  2. SeqIntention (Sequence): An adapted Transformer architecture that uses a "cross-attention" and "cross-resnet" mechanism. This allows the model to focus specifically on the relationship between added (+) and removed (-) lines.
  3. GraphIntention (Structure): A Graph Convolutional Network (GCN) approach that captures how the AST structure evolved from the "before" version to the "after" version.

Modeling Structural Intention

A key novelty of Patcherizer is its approach to structural intention. Instead of just comparing two ASTs, the model builds a "static graph" representing the entire training set's AST structures. Individual patches are then aligned to this graph, and a "graph-cross-resnet" is used to capture the mathematical "delta" between the old and new states in graph space.

The GraphIntention workflow: from AST parsing to intention graph embedding.

By using cross-resnet layers, Patcherizer explicitly calculates the difference between the "before" and "after" versions. This hybridity is powerful: the sequence encoder is better at spotting specific identifier names, while the graph encoder excels at recognizing the type of change (like adding a null check) even if variable names differ.

Experimental Evaluation

The study utilized several key datasets, including a set of 90,661 patches for description generation and 11,352 patches for correctness assessment. Patcherizer significantly outperformed state-of-the-art (SOTA) baselines like CC2Vec, FIRA, and CCRep across all tasks:

  • Commit Message Generation: Achieved an average improvement of 19.39% in BLEU, 8.71% in ROUGE-L, and 34.03% in METEOR scores.
  • Patch Correctness: In classifying whether a patch is a correct fix, Patcherizer reached an AUC of 0.96, outperforming BERT-based models (0.83) and CC2Vec (0.75).
  • Intention Detection: Qualitative analysis using t-SNE visualizations showed that Patcherizer is much better at clustering patches by their actual intent (e.g., "add," "remove," or "update") compared to previous models.

Conclusion and Future Directions

Patcherizer demonstrates that representing a patch isn't just about representing the new code; it's about representing the difference. While the model relies on the ability to parse code into a valid AST—which can be a limitation if code is unparsable—it sets a new benchmark for patch representation. Future work includes extending the tool to support more programming languages beyond Java and exploring its use in tasks like just-in-time defect prediction.

Summary updated

BibTeX
@inproceedings{tang2023learning,
  author = {Xunzhu Tang and Haoye Tian and Zhenghan Chen and Weiguo Pian and Saad Ezzini and Abdoul Kader Kaboré and Andrew Habib and Jacques Klein and Tegawendé F. Bissyandé},
  title = {{Learning to Represent Patches}},
  booktitle = {ICSE Companion},
  year = {2023},
  url = {https://openreview.net/forum?id=AcAwtBEE5a},
}
Figure