arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2306.01394cs.SE
收藏

领域知识至关重要:利用修复模板改进提示以修复 Python 类型错误

Domain Knowledge Matters: Improving Prompts with Fix Templates for Repairing Python Type Errors

Yun Peng, Shuzheng Gao, Cuiyun Gao, Yintong Huo, Michael R. Lyu

AI总结:

针对 Python 类型错误修复中提示缺乏领域知识的问题,本文提出 TypeFix,通过层次聚类挖掘通用修复模板并自适应生成提示,在两个基准上显著提升修复数量与补丁覆盖率。

摘要:

尽管 Python 的动态类型系统方便开发者编写 Python 程序,但也会在运行时带来类型错误。已有一些基于规则的方法可自动修复 Python 类型错误。这类方法能够生成准确的补丁,但需要领域专家设计补丁综合规则,并且对真实类型错误的模板覆盖率较低。基于学习的方法减轻了设计补丁综合规则所需的人工工作。在基于学习的方法中,基于提示的方法通过预定义提示利用代码预训练模型的知识库,在通用程序修复任务中取得了最先进的性能。然而,此类提示是人工定义的,不包含任何用于修复 Python 类型错误的特定线索,因此效果有限。如何利用类型错误修复的领域知识自动改进提示,既具有挑战性,也尚未得到充分研究。本文提出 TypeFix,这是一种融合修复模板、用于修复 Python 类型错误的新型基于提示方法。TypeFix 首先通过一种新颖的层次聚类算法挖掘通用修复模板。所识别出的修复模板表明了现有类型错误修复中常见的编辑模式和上下文。随后,TypeFix 将通用修复模板作为领域知识,为代码预训练模型生成代码提示;其中掩码会针对每个类型错误自适应定位,而不是预先确定。在 BugsInPy 和 TypeBugs 两个基准上的实验表明,TypeFix 成功修复了 26 个和 55 个类型错误,分别比最佳基线方法多修复 9 个和 14 个。此外,所提出的修复模板挖掘方法在两个基准上均可覆盖 75% 的开发者补丁,相比最佳基于规则的方法 PyTER 提升超过 30%。

英文摘要:

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%.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑