MultiFix: Learning to Repair Multiple Errors by Optimal Alignment Learning

HyeonTae Seo, Yo-Sub Han, Sang-Ki KoEMNLP 2021

Introduction

Automatic Program Repair (APR) aims to assist programmers—particularly novices—by automatically identifying and fixing bugs. While deep learning has significantly advanced this field, most existing models suffer from a "one-at-a-time" limitation. Current state-of-the-art tools typically localize a single error, suggest a fix, and require the user to re-compile to find the next error. This iterative process is slow and cumbersome for programs containing multiple disparate errors, such as a missing semicolon on one line and a typo on another. MultiFix addresses this by framing program repair as an optimal alignment problem, allowing for the simultaneous correction of multiple errors in a single pass.

Methods

The authors propose a sequence-to-sequence (seq2seq) framework that treats code repair as an alignment task rather than simple translation.

Optimal Alignment Learning

Instead of training the model to output the entire corrected program, MultiFix is trained to produce a sequence of edit operations—Insert, Delete, and Replace. These labels are generated using edit-distance algorithms to find the mathematically optimal path between the erroneous and corrected code. This approach forces the model to learn the structural relationship between tokens rather than just rewriting text.

Synchronized Position Embedding

In standard seq2seq models, position embeddings are static. However, during code repair, an "insertion" edit shifts the relative positions of all subsequent tokens. MultiFix introduces Synchronized Position Embedding: if the decoder predicts an insertion, the position counter remains the same for the next step. This ensures the model stays aligned with the specific token in the input sequence it is currently modifying.

Figure 1: Diagram of the MultiFix architecture showing the synchronized position embedding mechanism during edit operations.

Architecture

Interestingly, the authors found that a 4-layer bidirectional LSTM outperformed Transformers for the rigid, formal structure of C code. They hypothesize that standard self-attention mechanisms may not yet be perfectly tuned for the strict hierarchical dependencies of programming languages compared to natural languages. To enhance performance, they utilized Beam Search (width 100) to generate and evaluate multiple candidate fixes.

Datasets and Evaluation

The researchers evaluated MultiFix using the DeepFix Dataset, which contains over 37,000 correct and nearly 7,000 erroneous C programs from introductory courses. To expand the training variety, they used DrPerturb, a data augmentation procedure that creates "corrupted" versions of correct programs by injecting common errors.

Key Results

MultiFix achieved a new state-of-the-art performance on the DeepFix benchmark. As shown in the performance comparison, the model reached a Full Repair Rate (FRR) of 74.6% when combined with DrPerturb and Beam Search, significantly outperforming the previous best of 68.2% (DrRepair).

Figure 4: Performance comparison of MultiFix against baseline models on the DeepFix benchmark.

Ablation studies highlighted the importance of the synchronized position embedding, which alone boosted accuracy from 75.5% to 80.6% in controlled tests. Furthermore, MultiFix demonstrated superior efficiency by fixing multiple errors across different lines in a single iteration, whereas earlier models like DeepFix often required multiple passes to achieve the same result.

Conclusion and Future Work

MultiFix demonstrates that predicting edits through optimal alignment is more effective for program repair than standard translation. While LSTMs currently lead in this domain, future work will investigate architectural tweaks to make Transformers more "code-aware." Additionally, the authors suggest exploring more diverse sampling methods, such as Conditional Variational Autoencoders (CVAE), to address complex logic errors and testing the model's generalizability to other languages like Python or Java.

Summary updated

BibTeX
@inproceedings{seo2021multifix,
  author = {HyeonTae Seo and Yo-Sub Han and Sang-Ki Ko},
  title = {{MultiFix: Learning to Repair Multiple Errors by Optimal Alignment Learning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.findings-emnlp.417},
}
Figure