通过结构化预测学习代码特征与代码转换之间的关系
Learning the Relation between Code Features and Code Transforms with Structured Prediction
AI总结:
提出基于 CRF 的 AST 级代码转换结构化预测方法,并在 Java 修复转换预测中验证其准确率与补丁生成价值。
摘要:
为了有效指导自动化代码演化技术对代码转换空间的探索,本文提出了首个利用条件随机场(CRF)在 AST 节点层级结构化预测代码转换的方法。该方法首先离线学习一个概率模型,以刻画特定代码转换如何应用于特定 AST 节点,随后使用所学模型为任意新的、未见过的代码片段预测转换。我们的方法包含一种针对程序和代码转换的新颖表示。具体而言,我们引入了用于定义所谓 AST 级代码转换的形式化框架,并展示了如何相应地设计、学习 CRF 模型并将其用于预测。我们在 Java 程序的修复转换预测场景中实例化了该方法。该实例化包含一组精心设计的代码特征,处理训练数据不平衡问题,并纳入代码特有的转换约束。我们基于来自真实 Java 项目的缺陷修复提交数据集开展了大规模实验评估。结果表明,当采用常用评估指标 top-3 时,我们的方法预测代码转换的准确率根据转换类型不同在 41% 到 53% 之间变化。我们的模型优于基于历史概率和神经机器翻译(NMT)的两个基线,表明考虑代码结构对于获得良好预测准确率的重要性。此外,我们实现了一个概念验证合成器,用于具体化部分修复转换以获得最终补丁。该合成器在 Defects4j 基准上的评估证实,所预测的 AST 级修复转换有助于生成高质量补丁。
英文摘要:
To effectively guide the exploration of the code transform space for automated code evolution techniques, we present in this paper the first approach for structurally predicting code transforms at the level of AST nodes using conditional random fields (CRFs). Our approach first learns offline a probabilistic model that captures how certain code transforms are applied to certain AST nodes, and then uses the learned model to predict transforms for arbitrary new, unseen code snippets. {Our approach involves a novel representation of both programs and code transforms. Specifically, we introduce the formal framework for defining the so-called AST-level code transforms and we demonstrate how the CRF model can be accordingly designed, learned, and used for prediction}. We instantiate our approach in the context of repair transform prediction for Java programs. Our instantiation contains a set of carefully designed code features, deals with the training data imbalance issue, and comprises transform constraints that are specific to code. We conduct a large-scale experimental evaluation based on a dataset of bug fixing commits from real-world Java projects. The results show that when the popular evaluation metric \emph{top-3} is used, our approach predicts the code transforms with an accuracy varying from 41\% to 53\% depending on the transforms. Our model outperforms two baselines based on history probability and neural machine translation (NMT), suggesting the importance of considering code structure in achieving good prediction accuracy. In addition, a proof-of-concept synthesizer is implemented to concretize some repair transforms to get the final patches. The evaluation of the synthesizer on the Defects4j benchmark confirms the usefulness of the predicted AST-level repair transforms in producing high-quality patches.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。