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

On Multi-Modal Learning of Editing Source Code

Saikat Chakraborty, Baishakhi Ray

Abstract

Automated code editing tools often struggle because identical lines of code may require different fixes depending on the surrounding context and the developer's intent. This paper introduces MODIT, a multi-modal Neural Machine Translation (NMT) engine that combines the buggy code, the surrounding code context, and natural language guidance. By integrating these three modalities into a single-encoder Transformer architecture, MODIT generates highly accurate code patches, significantly outperforming existing state-of-the-art models like CodeBERT and GraphCodeBERT.

Introduction

Neural Machine Translation (NMT) has become a popular approach for automatically generating source code edits, such as bug fixes or refactoring. However, traditional NMT-based code editors typically only look at the specific lines of code that need changing. This creates a massive ambiguity problem: an identical snippet of code (e.g., pictures = new ArrayList<>()) might need to be changed to a HashSet in one scenario and a LinkedList in another.

Without understanding the intent behind the change or the context in which it occurs, automated tools are essentially guessing. They leave developers with a ranked list of possible patches where the correct answer isn't always at the top. This paper addresses the gap by asking: can we build a code editor that simultaneously reasons about the code, its local environment, and the developer's natural language instructions?

The MODIT Framework

The authors introduce MODIT, a transformer-based NMT engine that treats code editing as a multi-modal learning problem. Instead of just feeding the model the buggy code, MODIT integrates three distinct modalities:

  1. Edit Location ($e_p$): The specific code fragment that needs to be changed.
  2. Guidance (G): Natural language hints about the developer's intent (simulated in this study using commit messages).
  3. Context (C): The surrounding code (e.g., the full method body before the edit).

Architecture and Training

MODIT uses a 6-layer transformer encoder-decoder architecture initialized with PLBART, a foundational model pre-trained on massive amounts of source code. The model concatenates these three inputs into a single sequence separated by special <s> tokens.

A key architectural finding was that a single-encoder approach outperforms multi-encoder designs. By passing all modalities through one encoder, the transformer's self-attention mechanism can perform inter-modality reasoning. For example, it can directly link a word in the natural language guidance to a specific variable name in the code context. The model is then fine-tuned to output the exact tokens of the corrected code snippet.

Experimental Setup

The paper evaluates MODIT on two existing datasets introduced by Tufano et al., which consist of bug-fix commits extracted from Java projects on GitHub:

  • B2Fs: Contains smaller methods (up to 50 tokens in length).
  • B2Fm: Contains medium-sized methods (up to 100 tokens in length).

Each dataset example includes the method before the change, the method after the change, and the associated commit message, which serves as the natural language guidance.

Key Results and Insights

MODIT achieves state-of-the-art performance across both datasets, demonstrating the power of multi-modal integration:

  • Top-1 Accuracy: MODIT achieves 29.99% and 23.02% top-1 accuracy (exact match of the patched code) on the B2Fs and B2Fm datasets, respectively.
  • Comparative Performance: MODIT outperforms fine-tuned versions of CodeBERT (by up to 25.7%), GraphCodeBERT (by up to 34.4%), and CodeGPT (by up to 30.5%).
  • The Power of Pre-training: Initializing with PLBART weights improved performance by 167% compared to the best baseline model trained from scratch.
  • Modality Impact: Adding natural language guidance improved performance by up to 37.37%, while adding code context provided an additional 6.4% boost.

Why MODIT Works

The success of MODIT stems from how it utilizes its inputs. The Context provides the "ingredients," allowing the model to copy relevant variable and method names from the local environment. The Guidance narrows the search space, helping the model decide which valid transformation to apply (e.g., fixing a type error vs. refactoring). Finally, Isolating the Edit Site forces the model to focus its attention on the exact problem area rather than searching the entire method for the bug.

Limitations and Future Work

While MODIT represents a significant step forward, it has limitations. It currently assumes the exact location of the required edit is already known, typically provided by a fault localization tool. If the model is given a whole file without specific pointers, accuracy decreases. Additionally, the study uses commit messages as a proxy for guidance. Since commit messages are usually written after an edit, future research must determine if developers can provide effective guidance before the edit in a real-world IDE setting.

The authors suggest that future models might benefit from generating a sequence of edit operations (INSERT, DELETE, UPDATE) rather than raw tokens, which could improve precision for larger files.

Summary updated

BibTeX
@inproceedings{chakraborty2021multi,
  author = {Saikat Chakraborty and Baishakhi Ray},
  title = {{On Multi-Modal Learning of Editing Source Code}},
  booktitle = {ASE},
  year = {2021},
  doi = {10.1109/ase51524.2021.9678559},
}
Figure