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

Learning Structural Edits via Incremental Tree Transformations

Ziyu Yao, Frank F. Xu, Pengcheng Yin, Huan Sun, Graham Neubig

Most neural generative models are "one-and-done"—they generate an entire output in a single pass. However, the human creative process, especially programming, is inherently iterative. We write, debug, refactor, and polish. While previous work has explored "editing" models, they largely focus on sequential data (like text sentences) or perform the edit in a single pass. This is problematic for structured data like source code, which has a strict underlying syntax best represented as an Abstract Syntax Tree (AST). When you delete a function or move a block of code, you are performing a structural transformation. Existing models often struggle to maintain grammar validity or fail to capture the "intent" of an edit when the surface-level text looks different from training examples.

To address this, researchers have developed a neural editor that modifies tree-structured data through a sequence of incremental transformations rather than single-pass generation. By representing edits as actions on ASTs and using imitation learning to correct mistakes, the model achieves significantly higher accuracy in capturing the underlying intent of code changes.

The Neural Tree Editor

The authors propose treating editing as a sequential decision-making process. Instead of generating new code from scratch, the model starts with the original AST and applies a sequence of actions: Delete, Add, CopySubTree, and Stop.

Iterative tree edit generation process showing the model architecture and step-by-step transformations.

To keep the code syntactically valid at every step, the model uses the Abstract Syntax Description Language (ASDL) framework. When a node is deleted, it is replaced by a "Dummy" placeholder to maintain the tree structure until a new node is added.

The architecture consists of three main components:

  1. Tree Encoder: Uses a Gated Graph Neural Network (GGNN) to represent the current state of the code.
  2. History Encoder: An LSTM tracks the sequence of edits made so far.
  3. Edit Decoder: Predicts which operator to use, which node to target, and what value to insert.

A novel contribution is the TreeDiff Edit Encoder. Instead of just looking at the difference in text tokens, the model learns to represent the "intent" of an edit by encoding the sequence of actions required to transform the old tree into the new one.

To help the model recover from its own mistakes, the authors employ imitation learning via DAGGER (Dataset Aggregation) and introduce POSTREFINESAMPLING. This strategy allows the model to complete a full pass of edits and then learn from an "expert" how to fix any remaining discrepancies between its output and the goal.

Datasets and Key Results

The model was evaluated on two C# source code datasets: GitHubEdits (GHE) (over 100,000 real-world edit pairs) and C#Fixers (Fixers) (a smaller, high-quality dataset of specific refactorings used for "one-shot" evaluation).

By editing the AST directly, the model can ignore irrelevant "surface" differences. For instance, the CopySubTree operation acts as a highly efficient mechanism to move large blocks of existing code in a single step, proving much more robust than token-by-token generation. Furthermore, encoding the process of editing provides a more generalizable representation of user intent.

Performance comparison of models using Sequence vs. TreeDiff Edit Encoders across different datasets.

In the Fixers one-shot setting, the proposed editor (Graph2Edit) outperformed previous state-of-the-art models like Graph2Tree and CopySpan by more than 9% in macro-accuracy and 7% in micro-accuracy. Replacing standard sequence-based edit encoders with the proposed TreeDiff Edit Encoder led to a significant jump in performance across the board, proving that structural differences are more informative than token differences. Additionally, the imitation learning approach successfully taught the model to make more stable decisions, reducing the frequency of infinite editing loops.

Limitations and Future Work

Despite these advances, about 80% of the model's remaining errors were due to "unknown tokens"—variable or method names not present in the training vocabulary. Furthermore, the Fixers dataset is currently too small to train on directly for one-shot tasks, requiring pre-training on the larger GHE dataset.

Future directions include extending this framework to other structured tasks, such as grammar error correction in natural language or simplifying complex sentences. The authors also envision incorporating natural language "edit specifications" (e.g., a user prompting "Refactor this loop") to trigger these structural transformations.

Summary updated

BibTeX
@inproceedings{yao2021learning,
  author = {Ziyu Yao and Frank F. Xu and Pengcheng Yin and Huan Sun and Graham Neubig},
  title = {{Learning Structural Edits via Incremental Tree Transformations}},
  booktitle = {International Conference on Learning Representations},
  year = {2021},
  url = {https://openreview.net/forum?id=v9hAX77--cZ},
}
Figure