Skip to main content
QUICK REVIEW

[论文解读] Domain Knowledge Matters: Improving Prompts with Fix Templates for Repairing Python Type Errors

Yun Peng, Shuzheng Gao|arXiv (Cornell University)|Jun 2, 2023
Software Engineering Research被引用 4
一句话总结

该论文提出TypeFix,一种基于提示的改进方法,通过整合从真实世界补丁中挖掘出的领域特定修复模板,提升代码预训练模型在修复Python类型错误方面的性能。通过使用通用编辑模式自适应定位掩码,TypeFix提升了提示的有效性,在BugsInPy和TypeBugs数据集上分别实现了26次和55次成功修复,分别优于最佳基线方法9次和14次修复,且覆盖了75%的开发者补丁。

ABSTRACT

Although the dynamic type system of Python facilitates the developers in writing Python programs, it also brings type errors at run-time. There exist rule-based approaches for automatically repairing Python type errors. The approaches can generate accurate patches but they require domain experts to design patch synthesis rules and suffer from low template coverage of real-world type errors. Learning-based approaches alleviate the manual efforts in designing patch synthesis rules. Among the learning-based approaches, the prompt-based approach which leverages the knowledge base of code pre-trained models via pre-defined prompts, obtains state-of-the-art performance in general program repair tasks. However, such prompts are manually defined and do not involve any specific clues for repairing Python type errors, resulting in limited effectiveness. How to automatically improve prompts with the domain knowledge for type error repair is challenging yet under-explored. In this paper, we present TypeFix, a novel prompt-based approach with fix templates incorporated for repairing Python type errors. TypeFix first mines generalized fix templates via a novel hierarchical clustering algorithm. The identified fix templates indicate the common edit patterns and contexts of existing type error fixes. TypeFix then generates code prompts for code pre-trained models by employing the generalized fix templates as domain knowledge, in which the masks are adaptively located for each type error instead of being pre-determined. Experiments on two benchmarks, including BugsInPy and TypeBugs, show that TypeFix successfully repairs 26 and 55 type errors, outperforming the best baseline approach by 9 and 14, respectively. Besides, the proposed fix template mining approach can cover 75% of developers' patches in both benchmarks, increasing the best rule-based approach PyTER by more than 30%.

研究动机与目标

  • 解决手动定义的提示在修复Python类型错误方面效果有限的问题。
  • 减少在基于规则的方法中对专家设计的补丁合成规则的依赖。
  • 通过整合来自真实世界类型错误修复的领域知识,提升基于提示的程序修复性能。
  • 在现有基于规则的方法基础上,提升真实世界类型错误的模板覆盖范围。
  • 开发一种自动方法,利用挖掘出的修复模板生成上下文感知的、自适应的提示。

提出的方法

  • TypeFix首先使用一种新颖的分层聚类算法,从真实世界类型错误修复中挖掘通用修复模板。
  • 挖掘出的模板捕捉了类型错误修复中的常见编辑模式和语法上下文。
  • 该方法基于修复模板动态识别错误代码中最佳的掩码位置,替代静态提示设计。
  • 它将这些模板作为领域知识整合到提示中,用于代码预训练模型,从而提升其修复准确性。
  • 模型通过使用增强的、上下文感知的提示预测被掩码的标记来生成补丁。
  • 该方法在两个基准数据集BugsInPy和TypeBugs上进行评估,采用标准的程序修复评估指标。

实验结果

研究问题

  • RQ1从真实世界补丁中挖掘出的修复模板能否提升基于提示的Python类型错误修复性能?
  • RQ2基于修复模板的自适应掩码定位策略与固定、预定义的提示相比,在修复复杂类型错误时表现如何?
  • RQ3所提出的修复模板挖掘方法在覆盖范围上相比现有基于规则的方法能提升多少?
  • RQ4通过模板引入领域特定知识是否能带来比通用提示更高的修复成功率?
  • RQ5该方法在真实世界Python代码中多样的类型错误模式下表现有多强的鲁棒性?

主要发现

  • 在BugsInPy基准上,TypeFix成功修复了26个类型错误,优于最佳基线方法9次修复。
  • 在TypeBugs基准上,TypeFix实现了55次成功修复,优于最佳基线方法14次修复。
  • 修复模板挖掘方法在两个基准中均覆盖了75%的开发者补丁,相比最佳基于规则的方法PyTER,覆盖范围提升超过30%。
  • 自适应掩码定位策略相比静态、手动定义的提示,显著提升了修复有效性。
  • 将领域特定的修复模板集成到提示中,显著提升了修复准确率和泛化能力。
  • 该方法在多样化类型错误模式下表现出强大的泛化能力,表明其在真实世界场景中的鲁棒性。

更好的研究,从现在开始

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

无需绑定信用卡

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