一句话:首次系统评估神经机器翻译模型能否从 pull request 的代码改动中学习并自动复现开发者的修改。
近年来深度学习被广泛用于源代码相关任务,但学界仍缺乏关于「哪些代码改动可以被学习并自动施加」的实证证据。本文以 pull request 中开发者实际提交的改动为学习目标,构建了 236k 对改动前/后的代码组件,训练并评估一个神经机器翻译(NMT)模型来直接生成修改后的代码。定量结果显示:在足够窄的上下文(即改动前后成对的小/中型方法)下,NMT 能自动复现开发者改动的情形最高达 36%。进一步的定性分析表明,模型能够学习并复现多种有意义的代码改动,尤其是重构与缺陷修复。该工作为「深度学习用于代码」方向开辟了新议题,例如重构的自动学习与应用。
Recent years have seen the rise of Deep Learning (DL) techniques applied to source code. Researchers have exploited DL to automate several development and maintenance tasks, such as writing commit messages, generating comments and detecting vulnerabilities among others. One of the long lasting dreams of applying DL to source code is the possibility to automate non-trivial coding activities. While some steps in this direction have been taken (e.g., learning how to fix bugs), there is still a glaring lack of empirical evidence on the types of code changes that can be learned and automatically applied by DL. Our goal is to make this first important step by quantitatively and qualitatively investigating the ability of a Neural Machine Translation (NMT) model to learn how to automatically apply code changes implemented by developers during pull requests. We train and experiment with the NMT model on a set of 236k pairs of code components before and after the implementation of the changes provided in the pull requests. We show that, when applied in a narrow enough context (i.e., small/medium-sized pairs of methods before/after the pull request changes), NMT can automatically replicate the changes implemented by developers during pull requests in up to 36% of the cases. Moreover, our qualitative analysis shows that the model is capable of learning and replicating a wide variety of meaningful code changes, especially refactorings and bug-fixing activities. Our results pave the way for novel research in the area of DL on code, such as the automatic learning and applications of refactoring.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{abs-1901-09102,
title = {On Learning Meaningful Code Changes Via Neural Machine Translation},
author = {Michele Tufano and Jevgenija Pantiuchina and Cody Watson and Gabriele Bavota and Denys Poshyvanyk},
booktitle = {ICSE},
year = {2019},
doi = {10.1109/icse.2019.00021}
}