论文标题
Codeeditor:学习使用预训练模型编辑源代码
CodeEditor: Learning to Edit Source Code with Pre-trained Models
论文作者
论文摘要
开发人员在软件开发过程中经常出于各种原因(例如代码重构)进行重复的代码编辑活动。预先训练的代码编辑模型已实现了最新的(SOTA)结果。先培训的模型首先是通过预训练任务进行预训练的,并通过代码编辑任务进行微调。现有的预训练任务主要是代码填充任务(例如,掩盖语言建模),这些任务源自自然语言处理字段,并不是为自动代码编辑而设计的。 本文提出了一项专门从事代码编辑的新型预培训任务,并提出了一个有效的预训练的代码编辑模型,名为Codeeditor。我们的预训练任务进一步提高了代码编辑模型的性能和概括能力。具体来说,我们收集了许多现实世界代码片段作为基础真理,并使用强大的发电机将它们重写为突变的版本。然后,我们将编码器预先培训以将突变版本编辑为相应的地面真理,以学习编辑模式。我们在四个代码编辑数据集上进行实验,并在三个设置中评估预先训练的编码器。 (1)在微调设置中,我们使用四个数据集训练预先训练的编码器,然后在测试数据上对其进行评估。在四个数据集上,Codeeditor的表现优于SOTA基准的15%,25.5%和9.4%和26.6%。 (2)在几次设置中,我们使用有限的数据训练预先训练的编码器,并在测试数据上对其进行评估。 Codeeditor的性能比所有基准都更好。 (3)在零拍设置中,Codeeditor正确编辑了1,113个程序,而SOTA基线无法正常工作。
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. 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.