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

Learning to Represent Edits

Pengcheng Yin, Graham Neubig, Miltiadis Allamanis, Marc Brockschmidt, Alexander L. Gaunt

Introduction

In both natural language writing and software development, humans perform millions of incremental edits daily—polishing grammar, refactoring code, or fixing bugs. While automated tools exist to assist in these tasks, they typically rely on rigid, manually crafted rules. This research introduces a novel task: learning distributed representations of edits directly from data. By capturing the underlying semantics of a change, the authors demonstrate how to apply learned transformations to entirely new contexts, paving the way for sophisticated data-driven refactoring tools.

The Edit Representation Framework

The core of the proposed approach is an autoencoding framework designed to encode the difference between an original input ($x_-$) and its edited version ($x_+$). Unlike standard autoencoders that compress data points, this model compresses the transformation itself into a continuous vector space.

The high-level architecture showing how an edit representation is extracted from one context and applied to another via a Neural Editor.

As shown in the architecture above, the system consists of two primary components:

  1. The Edit Encoder ($f_\Delta$): This component acts as an information bottleneck. It takes the pair $(x_-, x_+)$ and produces an edit vector. The authors explored both sequence-based models (using LSTMs on token-level diffs) and graph-based models (using Gated Graph Neural Networks on merged Abstract Syntax Trees).
  2. The Neural Editor ($\alpha$): This decoder takes the original input $x_-$ and the edit vector to generate the edited output $x_+$. A key innovation here is a subtree copying mechanism, which allows the model to move entire structural blocks of code (like nested expressions) from the input to the output.

Methods and Datasets

The models were evaluated on both natural language (WikiAtomicEdits) and source code (GitHubEdits and C#Fixers). The GitHubEdits dataset contains over 111,000 real-world C# edits, while C#Fixers provides a gold-standard benchmark of 2,878 pairs generated by standard refactoring tools.

One significant finding was the trade-off between structural and sequential modeling. While graph-based encoders excel at abstract structural changes, sequence-based models often prove more effective at recognizing simple lexical tweaks, such as removing explicit type casting.

Key Results and Semantic Grouping

The neural models demonstrated a remarkable ability to group semantically equivalent edits. When humans rated the similarity of clustered edits, the neural models vastly outperformed bag-of-words baselines. For code edits, the Graph2Tree model achieved an NDCG@3 of 91.4%.

t-SNE visualization of learned edit representations, showing how semantically similar edits (labeled by their Roslyn analyzer IDs) cluster together in the vector space.

Beyond grouping, the models achieved strong performance in one-shot edit transfer. On the C#Fixers dataset, the Graph2Tree editor successfully applied a learned edit to a new context with 49.2% accuracy, compared to only ~8% for models lacking an edit encoder. This suggests the model can effectively extract the "intent" of a refactoring from a single example.

Conclusion

By learning to represent edits as continuous vectors, this work enables a new class of "one-shot" transfer learning for text and code manipulation. While complex logical reasoning—such as identifying redundant parentheses in deep math expressions—remains a challenge, these distributed representations provide a foundation for automatically synthesizing interpretable refactoring rules and building more intelligent, context-aware editing assistants.

Summary updated

BibTeX
@inproceedings{yin2019learning,
  author = {Pengcheng Yin and Graham Neubig and Miltiadis Allamanis and Marc Brockschmidt and Alexander L. Gaunt},
  title = {{Learning to Represent Edits}},
  booktitle = {International Conference on Learning Representations},
  year = {2019},
  url = {https://openreview.net/forum?id=v2NNoPl0TGT},
}
Figure