Skip to main content
QUICK REVIEW

[Paper Review] Patching as Translation: The Data and the Metaphor

Yangruibo Ding, Baishakhi Ray|arXiv (Cornell University)|May 8, 2020
Artistic and Creative ResearchArts and Humanities33 references11 citations
TL;DR

This paper challenges the prevalent metaphor of 'patching as translation' in automated program repair, demonstrating that neural machine translation (NMT) models designed for language tasks perform poorly on code repair due to fundamental mismatches in task design, architecture, and loss objectives. Through empirical analysis and a novel sequence-to-sequence model that generates edits conditionally on buggy context, the authors show that context-aware edit generation significantly outperforms NMT-based translation approaches, especially in handling minimal, high-impact code changes.

ABSTRACT

Machine Learning models from other fields, like Computational Linguistics, have been transplanted to Software Engineering tasks, often quite successfully. Yet a transplanted model's initial success at a given task does not necessarily mean it is well-suited for the task. In this work, we examine a common example of this phenomenon: the conceit that "software patching is like language translation". We demonstrate empirically that there are subtle, but critical distinctions between sequence-to-sequence models and translation model: while program repair benefits greatly from the former, general modeling architecture, it actually suffers from design decisions built into the latter, both in terms of translation accuracy and diversity. Given these findings, we demonstrate how a more principled approach to model design, based on our empirical findings and general knowledge of software development, can lead to better solutions. Our findings also lend strong support to the recent trend towards synthesizing edits of code conditional on the buggy context, to repair bugs. We implement such models ourselves as "proof-of-concept" tools and empirically confirm that they behave in a fundamentally different, more effective way than the studied translation-based architectures. Overall, our results demonstrate the merit of studying the intricacies of machine learned models in software engineering: not only can this help elucidate potential issues that may be overshadowed by increases in accuracy; it can also help innovate on these models to raise the state-of-the-art further. We will publicly release our replication data and materials at https://github.com/ARiSE-Lab/Patch-as-translation.

Motivation & Objective

  • To investigate the validity of the metaphor 'software patching is like language translation' in automated program repair.
  • To identify and empirically demonstrate critical mismatches between neural machine translation (NMT) models and the task of program repair.
  • To evaluate how architectural design, task formulation, and loss functions in NMT models hinder effective code repair.
  • To propose and evaluate a more principled, context-aware model that generates edits conditionally on buggy code, rather than translating entire sequences.
  • To provide empirical evidence that edit-based modeling outperforms translation-based modeling in terms of accuracy, diversity, and syntactic correctness.

Proposed method

  • The authors conduct a systematic empirical case study comparing NMT-based patch generation with a novel edit-based sequence-to-sequence model that conditions on the buggy context.
  • They evaluate models using standard metrics: exact match accuracy, top-5 accuracy with beam search, and teacher forcing during training.
  • The study incorporates increasing amounts of surrounding code context (up to 500 tokens) to assess its impact on model performance.
  • The proposed model generates edits rather than full sequences, focusing on the minimal changes required to fix bugs, which better aligns with real-world repair patterns.
  • Empirical analysis includes ablation studies on context length, attention mechanisms, and model capacity to isolate failure modes.
  • The authors release replication data and code to support reproducibility and further research.

Experimental results

Research questions

  • RQ1To what extent does the 'patching as translation' metaphor accurately reflect the underlying mechanics of automated program repair?
  • RQ2How do architectural choices in NMT models—particularly auto-regressive decoding and sequence-to-sequence generation—hinder effective code repair?
  • RQ3Why does the standard NMT loss function, based on token overlap (e.g., BLEU), fail to correlate with the quality of program repairs?
  • RQ4Can a context-aware edit-generation model outperform standard NMT-based patch generation in terms of accuracy and syntactic correctness?
  • RQ5What role does surrounding code context play in enabling accurate and diverse patch generation, and why is it difficult to integrate effectively in NMT models?

Key findings

  • NMT models trained for translation perform poorly on program repair due to the mismatch between the auto-regressive generation of entire sequences and the reality that most code patches involve only minimal, localized changes.
  • The standard NMT loss function based on token overlap (e.g., BLEU) correlates poorly with actual repair quality because many correct patches differ by only one or two tokens, leading to low BLEU scores despite high correctness.
  • Models trained on buggy code alone fail to generate correct patches due to insufficient context, and adding up to 500 tokens of context does not significantly improve performance, suggesting fundamental modeling limitations.
  • The proposed edit-based model, which generates patches conditionally on the buggy context, achieves significantly higher accuracy and better diversity than NMT-based models, especially in handling minimal changes.
  • The attention mechanism in NMT models fails to effectively locate the relevant bug locations, even when context is provided, indicating architectural incompatibility with repair tasks.
  • The study reveals that current NMT-based tools for program repair are not only suboptimal but may be fundamentally misaligned with the task, highlighting the need for principled model redesign.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.