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

Evaluating Representation Learning of Code Changes for Predicting Patch Correctness in Program Repair

Haoye Tian, Kui Liu, Abdoul Kader Kaboreé, Anil Koyuncu, Li Li, Jacques Klein, Tegawendé F. BissyandéarXiv 2020

This paper, presented at ASE 2020, explores a critical bottleneck in Automated Program Repair (APR): the "overfitting" problem. While APR tools are getting better at generating patches that pass test suites, these patches are often logically incorrect—they satisfy the test oracle but fail to capture the developer's true intent. The authors investigate whether deep representation learning (embeddings) can statically predict patch correctness without needing to execute expensive test suites.

TL;DR

The authors evaluate four different code embedding techniques to predict whether an automatically generated patch is actually correct. They find that a simple Logistic Regression model using BERT-based embeddings achieves an AUC of 0.8, demonstrating that static code features can effectively filter out incorrect patches and complement existing dynamic analysis methods.

What Problem Does This Paper Address?

In the world of Automated Program Repair, a patch is considered "plausible" if it passes all existing test cases. However, because test suites are often incomplete, many plausible patches are actually incorrect—a phenomenon known as overfitting.

Current state-of-the-art methods to detect these duds usually rely on:

  1. Dynamic Information: Running the patched program and comparing execution traces (e.g., PATCH-SIM). This is computationally expensive.
  2. Manual Heuristics: Using hand-crafted rules to identify suspicious code changes. These are hard to generalize across different programming languages.

This paper asks: Can we use deep learning to automatically learn features of "correctness" directly from the code changes themselves?

Methods

The researchers compared four distinct representation learning models to see which best captures the nuances of a "good" patch:

  • Doc2Vec: An unsupervised model trained on a large corpus of patches.
  • BERT: A deep transformer model pre-trained on natural language (Wikipedia).
  • code2vec: A model pre-trained on 14 million Java code snippets, focusing on Abstract Syntax Tree (AST) paths.
  • CC2Vec: A specialized model designed specifically to represent code changes (patches) guided by commit messages.

The workflow involves extracting the "buggy" and "patched" code fragments (as shown in Figure 4), converting them into high-dimensional vectors, and then using these vectors in two ways:

  1. Similarity Analysis: Measuring the cosine similarity between the buggy and patched vectors.
  2. Supervised Classification: Training machine learning models (Logistic Regression, Decision Trees, Naive Bayes) on "crossed" features—mathematical combinations of the buggy and patched vectors (subtraction, multiplication, etc.) to capture the relationship between the two states.
Figure 4: Producing code fragment embeddings with BERT, Doc2Vec and code2vec.

Datasets

The study utilized a massive collection of Java patches totaling 102,041 samples across several well-known benchmarks:

  • Developer Patches (Ground Truth Correct): Bears, Bugs.jar, Defects4J, ManySStuBs4J, and QuixBugs.
  • APR-Generated Patches: Samples from the RepairThemAll framework and a labeled dataset from Liu et al.
  • Evaluation Set: A deduplicated dataset of 1,000 labeled patches (468 correct, 532 incorrect) was used for the final machine learning classification experiments.

Key Insights and Ideas

  • The "Minimal Change" Hypothesis: The study statistically confirms that correct patches tend to have very high similarity to the original buggy code. As seen in Figure 6, similarity scores for correct patches are consistently high across different benchmarks.
  • BERT's Surprising Versatility: Despite being trained on Wikipedia text, BERT outperformed code-specific models like code2vec in several tasks. The authors suggest BERT's deep architecture allows it to capture subtle semantic relationships that shallower, code-specific models might miss.
  • Static vs. Dynamic: While dynamic tools like PATCH-SIM are slightly more accurate, the static embedding approach is "zero-shot" (doesn't require test execution) and can filter out up to 94.9% of incorrect patches using BERT-based thresholds.
  • Complementary Strengths: The deep-learned features appear to be complementary to manually engineered features. Combining them could lead to even more robust patch validation in the future.
Distributions of similarity scores between correct and buggy code fragments.

Key Results

  • Filtering Power: Using a similarity threshold, BERT was able to filter out 94.9% of incorrect patches in the QuixBugs dataset.
  • Classification Performance: A Logistic Regression classifier using BERT embeddings achieved an AUC of 0.808 and an F1-measure of 0.72.
  • Comparison to SOTA: In a head-to-head comparison on a specific test set, the BERT+LR model excluded 39.4% of incorrect patches without misclassifying a single correct one, compared to 56.3% for the dynamic PATCH-SIM tool.

Limitations and Future Work

  • Small Training Data: The supervised learning part of the study used only 1,000 labeled patches. The authors note that models like ODS were trained on 13,000+ samples, suggesting their results are a conservative estimate of what deep learning can achieve.
  • Zero-Shot Scenario: The models were used as-is without fine-tuning on code-specific tasks. Future work will involve fine-tuning models like CodeBERT specifically for patch correctness.
  • Fragment Size: Very small code changes (1-2 words) result in very high similarity scores regardless of correctness, making them harder to distinguish (Figure 11).
  • Manual Labeling: The ground truth for APR-generated patches relies on manual assessment, which is subject to human error.

Summary updated

BibTeX
@misc{tian2020evaluating,
  author = {Haoye Tian and Kui Liu and Abdoul Kader Kaboreé and Anil Koyuncu and Li Li and Jacques Klein and Tegawendé F. Bissyandé},
  title = {{Evaluating Representation Learning of Code Changes for Predicting Patch Correctness in Program Repair}},
  year = {2020},
  eprint = {2008.02944},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2008.02944},
}
Figure