CodeEditor: Learning to Edit Source Code with Pre-trained Models

Jia Li, Ge Li, Zhuo Li, Zhi Jin, Xing Hu +2 more
10/31/2022
cs.SEcs.AI

Official code: LJ2lijia/CodeEditor (6 stars, Python, last commit 2024-02-20).

Abstract

Developers often perform repetitive code editing activities for various reasons (e.g., code refactoring) during software development. Pre-trained code editing models have achieved the state-of-the-art (SOTA) results.

Show full abstract

Pre-trained models are first pre-trained with pre-training tasks and fine-tuned with the code editing task. Existing pre-training tasks mainly are code infilling tasks (e.g., masked language modeling), which are derived from the natural language processing field and are not designed for automatic code editing. This paper proposes a novel pre-training task specialized in code editing and presents an effective pre-trained code editing model named CodeEditor. Our pre-training task further improves the performance and generalization ability of code editing models. Specifically, we collect lots of real-world code snippets as the ground truth and use a powerful generator to rewrite them into mutated versions. Then, we pre-train our CodeEditor to edit mutated versions into the corresponding ground truth, to learn edit patterns. We conduct experiments on four code editing datasets and evaluate the pre-trained CodeEditor in three settings. (1) In the fine-tuning setting, we train the pre-trained CodeEditor with four datasets and evaluate it on the test data. CodeEditor outperforms the SOTA baselines by 15%, 25.5%, and 9.4% and 26.6% on four datasets. (2) In the few-shot setting, we train the pre-trained CodeEditor with limited data and evaluate it on the test data. CodeEditor substantially performs better than all baselines. (3) In the zero-shot setting, CodeEditor correctly edits 1,113 programs while the SOTA baselines can not work.

View on arXivView PDF

Code Implementations(1)

Offical implementation of our paper - CodeEditor in TOSEM

60Python, ShellApr 24, 20232 years ago

Similar Papers

Cite this paper

@article{li2022codeeditor,
  title  = {CodeEditor: Learning to Edit Source Code with Pre-trained Models},
  author = {Jia Li and Ge Li and Zhuo Li and Zhi Jin and Xing Hu and Kechi Zhang and Zhiyi Fu},
  year   = {2022},
  eprint = {2210.17040},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2210.17040}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2210.17040.svg)](https://codeofpaper.com/paper/2210.17040)

Discussion