Skip to main content
QUICK REVIEW

[论文解读] Neural Networks for Modeling Source Code Edits

Rui Zhao, David Bieber|arXiv (Cornell University)|Apr 4, 2019
Software Engineering Research参考文献 22被引用 12
一句话总结

本文将源代码编辑建模为序列预测,以推断开发者意图,采用双头注意力神经网络结合指针网络,预测编辑位置和内容。该模型在谷歌代码库的真实细粒度编辑序列上实现了高准确率和可扩展性,证明了其在意图感知型开发工具中的可行性。

ABSTRACT

Programming languages are emerging as a challenging and interesting domain for machine learning. A core task, which has received significant attention in recent years, is building generative models of source code. However, to our knowledge, previous generative models have always been framed in terms of generating static snapshots of code. In this work, we instead treat source code as a dynamic object and tackle the problem of modeling the edits that software developers make to source code files. This requires extracting intent from previous edits and leveraging it to generate subsequent edits. We develop several neural networks and use synthetic data to test their ability to learn challenging edit patterns that require strong generalization. We then collect and train our models on a large-scale dataset of Google source code, consisting of millions of fine-grained edits from thousands of Python developers. From the modeling perspective, our main conclusion is that a new composition of attentional and pointer network components provides the best overall performance and scalability. From the application perspective, our results provide preliminary evidence of the feasibility of developing tools that learn to predict future edits.

研究动机与目标

  • 将基于过去编辑序列预测未来代码编辑的问题形式化,将代码视为动态过程而非静态快照。
  • 开发能够从历史编辑中泛化编辑模式的神经网络架构,捕捉未来更改的位置和内容。
  • 在合成数据上评估模型性能,以检验其泛化能力;在谷歌代码库的真实数据上评估其可扩展性和实际可行性。
  • 探讨显式与隐式表示编辑序列在准确率和计算效率之间的权衡。

提出的方法

  • 本文提出一种隐式表示编辑序列的方法,通过存储初始代码状态和后续的(位置,内容)对来提升可扩展性。
  • 提出一种双头注意力模型,其中一个头用于预测编辑位置,另一个头使用指针网络生成编辑内容。
  • 模型使用自注意力机制编码编辑历史,捕捉编辑序列中的长距离依赖关系。
  • 采用分层循环指针网络作为强基线模型,用于对比评估,尽管计算成本较高。
  • 构建合成数据集以评估模型的特定能力,例如从编辑模式中识别意图。
  • 在谷歌真实Python代码库的100万+个细粒度编辑的大型数据集上训练和评估模型。

实验结果

研究问题

  • RQ1神经网络能否通过分析过去编辑序列,有效预测未来代码编辑,即使相同代码状态可能由不同的编辑历史导致?
  • RQ2显式(完整状态快照)与隐式(类似diff的编辑)表示在模型可扩展性和泛化能力方面有何影响?
  • RQ3哪些架构组件(如注意力机制、指针网络)能在准确率、置信度校准和计算效率之间实现最佳权衡?
  • RQ4模型在多大程度上能泛化到需要理解开发者意图而非仅表面更改的未见编辑模式?
  • RQ5此类模型能否应用于真实世界的大规模代码库,以支持实用的开发工具?

主要发现

  • 带有指针网络头的双头注意力模型在真实编辑序列上的准确率和可扩展性方面优于其他架构。
  • 模型实现了校准良好的置信度估计,表明其对预测不确定性的量化可靠。
  • 显式表示可实现高准确率但可扩展性差,而隐式表示虽具可扩展性,但若缺乏恰当的架构设计则难以实现泛化。
  • 合成数据实验表明,模型能够学习需要强泛化能力的复杂编辑模式,例如根据编辑历史区分添加或删除函数参数。
  • 结果提供了初步证据,表明在编辑序列上训练的模型能够学习开发者意图,从而为未来智能代码辅助工具提供支持。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。