Skip to main content
QUICK REVIEW

[论文解读] Patching as Translation: The Data and the Metaphor

Yangruibo Ding, Baishakhi Ray|arXiv (Cornell University)|May 8, 2020
Artistic and Creative Research参考文献 33被引用 11
一句话总结

本文挑战了自动化程序修复中‘补丁即翻译’这一普遍隐喻,表明为语言任务设计的神经机器翻译(NMT)模型在代码修复任务中表现不佳,原因在于任务设计、模型架构和损失目标之间存在根本性不匹配。通过实证分析及一种基于错误代码上下文条件生成修改的新型序列到序列模型,作者证明上下文感知的修改生成方法显著优于基于NMT的翻译方法,尤其在处理微小但影响重大的代码更改方面表现更优。

ABSTRACT

Machine Learning models from other fields, like Computational Linguistics, have been transplanted to Software Engineering tasks, often quite successfully. Yet a transplanted model's initial success at a given task does not necessarily mean it is well-suited for the task. In this work, we examine a common example of this phenomenon: the conceit that "software patching is like language translation". We demonstrate empirically that there are subtle, but critical distinctions between sequence-to-sequence models and translation model: while program repair benefits greatly from the former, general modeling architecture, it actually suffers from design decisions built into the latter, both in terms of translation accuracy and diversity. Given these findings, we demonstrate how a more principled approach to model design, based on our empirical findings and general knowledge of software development, can lead to better solutions. Our findings also lend strong support to the recent trend towards synthesizing edits of code conditional on the buggy context, to repair bugs. We implement such models ourselves as "proof-of-concept" tools and empirically confirm that they behave in a fundamentally different, more effective way than the studied translation-based architectures. Overall, our results demonstrate the merit of studying the intricacies of machine learned models in software engineering: not only can this help elucidate potential issues that may be overshadowed by increases in accuracy; it can also help innovate on these models to raise the state-of-the-art further. We will publicly release our replication data and materials at https://github.com/ARiSE-Lab/Patch-as-translation.

研究动机与目标

  • 探究‘软件补丁生成如同语言翻译’这一隐喻在自动化程序修复中的有效性。
  • 识别并实证证明神经机器翻译(NMT)模型与程序修复任务之间存在的关键不匹配。
  • 评估NMT模型在架构设计、任务定义和损失函数方面如何阻碍有效的代码修复。
  • 提出并评估一种更具原则性、基于上下文感知的模型,该模型基于错误代码条件生成修改,而非翻译完整序列。
  • 提供实证证据表明,基于修改的建模在准确率、多样性及语法正确性方面优于基于翻译的建模。

提出的方法

  • 作者开展了一项系统性的实证案例研究,比较基于NMT的补丁生成与一种新型基于修改的序列到序列模型,后者基于错误代码上下文进行生成。
  • 采用标准指标评估模型:精确匹配准确率、使用束搜索的Top-5准确率,以及训练期间的教师强制策略。
  • 研究逐步增加周围代码上下文(最多500个标记)以评估其对模型性能的影响。
  • 所提出的模型生成的是修改而非完整序列,聚焦于修复错误所需的最小更改,更符合现实中的修复模式。
  • 实证分析包括对上下文长度、注意力机制和模型容量的消融研究,以隔离失败模式。
  • 作者发布了复制数据和代码,以支持可复现性及进一步研究。

实验结果

研究问题

  • RQ1‘补丁即翻译’这一隐喻在多大程度上准确反映了自动化程序修复的底层机制?
  • RQ2NMT模型中的架构选择——特别是自回归解码和序列到序列生成——在多大程度上阻碍了有效的代码修复?
  • RQ3为何基于标记重叠(如BLEU)的标准NMT损失函数无法与程序修复质量相关联?
  • RQ4基于上下文的修改生成模型是否能在准确率和语法正确性方面优于标准的NMT基补丁生成模型?
  • RQ5周围代码上下文在实现准确且多样的补丁生成中起到何种作用?为何在NMT模型中难以有效整合?

主要发现

  • 为翻译任务训练的NMT模型在程序修复任务中表现不佳,原因在于其自回归生成完整序列的方式与大多数代码补丁仅涉及微小、局部更改的现实严重不符。
  • 基于标记重叠(如BLEU)的标准NMT损失函数与实际修复质量相关性差,因为许多正确补丁仅相差一个或两个标记,导致BLEU分数低但修复正确。
  • 仅在错误代码上训练的模型无法生成正确补丁,因上下文不足;即使增加最多500个标记的上下文,性能也未显著提升,表明存在根本性的建模局限。
  • 所提出的基于修改的模型,即基于错误代码上下文条件生成补丁,其准确率和多样性显著优于NMT基模型,尤其在处理微小更改方面表现更优。
  • NMT模型中的注意力机制即使在提供上下文的情况下,也难以有效定位相关错误位置,表明其架构与修复任务存在不兼容性。
  • 本研究揭示,当前基于NMT的程序修复工具不仅效率低下,甚至在根本上与任务目标错位,凸显了对模型进行原则性重构的迫切需求。

更好的研究,从现在开始

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

无需绑定信用卡

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