HyperAIHyperAI
2 months ago

A Structural Model for Contextual Code Changes

Brody, Shaked ; Alon, Uri ; Yahav, Eran
A Structural Model for Contextual Code Changes
Abstract

We address the problem of predicting edit completions based on a learnedmodel that was trained on past edits. Given a code snippet that is partiallyedited, our goal is to predict a completion of the edit for the rest of thesnippet. We refer to this task as the EditCompletion task and present a novelapproach for tackling it. The main idea is to directly represent structuraledits. This allows us to model the likelihood of the edit itself, rather thanlearning the likelihood of the edited code. We represent an edit operation as apath in the program's Abstract Syntax Tree (AST), originating from the sourceof the edit to the target of the edit. Using this representation, we present apowerful and lightweight neural model for the EditCompletion task. We conduct a thorough evaluation, comparing our approach to a variety ofrepresentation and modeling approaches that are driven by multiple strongmodels such as LSTMs, Transformers, and neural CRFs. Our experiments show thatour model achieves a 28% relative gain over state-of-the-art sequential modelsand 2x higher accuracy than syntactic models that learn to generate the editedcode, as opposed to modeling the edits directly. Our code, dataset, and trained models are publicly available athttps://github.com/tech-srl/c3po/ .

A Structural Model for Contextual Code Changes | Latest Papers | HyperAI