Adapting Deep Learning (DL) techniques to automate non-trivial coding activities, such as code documentation and defect detection, has been intensively studied recently. Learning to predict code changes is one of the popular and essential investigations. Prior studies have shown that DL techniques such as Neural Machine Translation (NMT) can benefit meaningful code changes, including bug fixing and code refactoring. However, NMT models may encounter bottleneck when modeling long sequences, thus are limited in accurately predicting code changes. In this work, we design a Transformer-based approach, considering that Transformer has proven effective in capturing long-term dependencies. Specifically, we propose a novel model named DTrans. For better incorporating the local structure of code, i.e., statement-level information in this paper, DTrans is designed with dynamically relative position encoding in the multi-head attention of Transformer. Experiments on benchmark datasets demonstrate that DTrans can more accurately generate patches than the state-of-the-art methods, increasing the performance by at least 5.45\%-46.57\% in terms of the exact match metric on different datasets. Moreover, DTrans can locate the lines to change with 1.75\%-24.21\% higher accuracy than the existing methods.
翻译:最近已经深入研究了如何调整深层学习(DL)技术以使非三角编码活动(如代码文档和缺陷检测)自动化。学习预测代码变化是受欢迎和必不可少的调查之一。先前的研究显示,神经机器翻译(NMT)等DL技术可以有利于有意义的代码变化,包括错误修正和代码再设置。然而,NMT模型在长序列建模时可能会遇到瓶颈,因此在准确预测代码变化方面受到限制。在这项工作中,我们设计了一个基于变换器的方法,考虑到变换器已证明在捕捉长期依赖性方面是有效的。具体地说,我们提出了一个名为DTrans的新模型。为了更好地纳入代码的本地结构,即本文中的语句级信息,DTrans在设计时,在变换器多头注意时,会以动态相对的位置编码方式设计。基准数据集实验表明,DTrans可以比最新的方法更准确地生成补丁。在精确精确精确精确度1至24数据设置上至少5.45 ⁇ 4.57 ⁇ 增加性。此外,DLORT在精确度上可以定位到高于1.75公制方法的行。