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

The Best of Both Worlds: Combining Learned Embeddings with Engineered Features for Accurate Prediction of Correct Patches

Haoye Tian, Kui Liu, Yinghua Li, Abdoul Kader Kaboré, Anil Koyuncu, Andrew Habib, Li Li 0029, Junhao Wen, Jacques Klein, Tegawendé F. Bissyandé

TL;DR

Automated Program Repair (APR) often produces "overfitting" patches that pass tests but are actually incorrect. This paper introduces Panther, a framework that combines deep learned code embeddings with manually engineered static features to identify correct patches with significantly higher accuracy than previous state-of-the-art dynamic or static methods.

What Problem Does This Paper Address?

The "holy grail" of software engineering is Automated Program Repair (APR)—tools that can automatically fix bugs. Most current APR systems use a "generate-and-validate" approach: they create many candidate patches and test them against a test suite.

The problem? Test suites are often incomplete. A patch might pass every test (making it plausible) but still be wrong because it breaks untested functionality or introduces a "lazy" fix (making it incorrect). This is known as the overfitting problem. Distinguishing a truly correct patch from a merely plausible one is a massive challenge. Existing solutions either rely on expensive dynamic execution traces or manually crafted heuristics that don't always generalize.

Methods

The authors investigate whether "learning" what a correct patch looks like is better than "defining" it. They propose a two-stage approach:

  1. Leopard (Learned Embeddings): A framework that uses deep learning models to represent code changes as vectors (embeddings). They tested four models:
  2. BERT: A natural language model pre-trained on Wikipedia (surprisingly effective for code).
  3. Doc2Vec: An unsupervised document-level embedding.
  4. code2vec: A model that represents code based on its Abstract Syntax Tree (AST) paths.
  5. CC2Vec: A model specifically designed to represent code changes (commits).
  6. Panther (The Hybrid Upgrade): This is the "Best of Both Worlds" contribution. It combines the learned embeddings from Leopard with Engineered Features (from a system called ODS), which include 195 manually defined characteristics like repair patterns and contextual syntax.

To combine these different types of data, they used three strategies:

  • Ensemble Learning: Averaging the predictions of separate classifiers.
  • Naïve Vector Concatenation: Smashing the feature vectors together into one long list.
  • Deep Combination: Using a "Double-DNN-fusion" architecture to let a neural network learn the best way to weigh both feature sets.

Datasets

The study utilized a massive collection of Java patches:

  • Similarity Analysis: ~102,000 patches from benchmarks like Bears, Bugs.jar, Defects4J, and QuixBugs.
  • Classification Training: A newly curated, high-quality labeled dataset of 2,147 patches (1,199 correct, 948 incorrect). This dataset is a significant contribution, as it deduplicates and cleans up several previous smaller benchmarks.

Key Insights and Ideas

  • BERT is a "Code" Powerhouse: Despite being trained on English prose (Wikipedia), BERT’s deep architecture allowed it to capture code semantics better than some models specifically designed for code changes.
  • Similarity is Necessary but Not Sufficient: Correct patches are generally more similar to the original buggy code than incorrect ones. However, the distributions overlap so much that a simple "similarity threshold" (e.g., "only accept patches 99% similar to the original") would either miss many correct fixes or let too many bugs through.
  • Complementary Strengths: SHAP (an explainability tool) revealed that learned embeddings and engineered features look at different things. Engineered features are great at spotting specific "bad patterns," while learned embeddings capture the "vibe" or semantic flow of the logic.
  • The "Single Line" Myth: One surprising finding from the feature analysis was that patches modifying only a single line were often more likely to be incorrect in certain contexts, challenging the common heuristic that "smaller is always better."

Key Results

  • Superior Prediction: The Leopard framework (using BERT + XGBoost) achieved an AUC of 0.803, outperforming the dynamic state-of-the-art tool (PATCH-SIM).
  • Hybrid Wins: Panther (the combined model) outperformed the embedding-only version across the board.
  • Recall Gains: Using Ensemble Learning, the authors reached a +Recall of 83.7% (the ability to find correct patches).
  • Filtering Power: Using the Deep Combination (DNN) approach, they achieved the best -Recall of 69.6%, meaning they could successfully filter out nearly 70% of the "plausible but wrong" patches that usually plague APR tools.

Limitations and Future Work

  • Parsing Failures: The code2vec model struggled significantly with "syntax-incomplete" code fragments (like small diffs), leading to high failure rates during feature extraction.
  • Language Specificity: The study focused entirely on Java. While the methodology is general, the specific engineered features and pre-trained models might perform differently for Python or C++.
  • Integration: The current work is a post-processing filter. The authors suggest that future work should involve integrating these models directly into the "search" phase of APR tools to prevent incorrect patches from being generated in the first place.

Summary updated

BibTeX
@article{tian2023best,
  author = {Haoye Tian and Kui Liu and Yinghua Li and Abdoul Kader Kaboré and Anil Koyuncu and Andrew Habib and Li Li and Junhao Wen and Jacques Klein and Tegawendé F. Bissyandé},
  title = {{The Best of Both Worlds: Combining Learned Embeddings with Engineered Features for Accurate Prediction of Correct Patches}},
  journal = {ACM Trans. Softw. Eng. Methodol.},
  year = {2023},
  doi = {10.1145/3576039},
}
Figure