LecPrompt:一种基于提示的利用CodeBERT进行逻辑错误纠正的方法
LecPrompt: A Prompt-based Approach for Logical Error Correction with CodeBERT
AI总结:
本文提出基于提示和CodeBERT的LecPrompt方法,通过计算困惑度定位逻辑错误并构建MLM任务自回归修复错误token,在QuixBugs-LE数据集上实现较高修复准确率。
摘要:
编程中的逻辑错误不会引发编译器警告,使其难以被检测。这些静默错误可能破坏程序功能或导致运行时问题。纠正这些错误需要对程序逻辑有深刻理解,凸显了自动化检测与修复的重要性。本文提出LecPrompt,一种基于提示的方法,利用在代码上训练的基于Transformer的大型语言模型CodeBERT的能力来定位和修复逻辑错误。首先,LecPrompt利用大型语言模型计算困惑度和对数概率指标,在token和行级别精确定位逻辑错误。通过统计分析,它识别出与大型语言模型识别的预期模式显著偏离的token和行,将其标记为潜在错误源。其次,通过将逻辑错误纠正挑战构建为掩码语言建模(MLM)任务,LecPrompt采用CodeBERT自回归地修复已识别的错误token。最后,软提示方法在低成本场景中提供了一种新颖解决方案,确保模型能够针对逻辑错误纠正任务的特定细微差别进行微调,而不会产生高昂的计算成本。为评估LecPrompt的性能,我们创建了一种将逻辑错误引入正确代码的方法,并将其应用于QuixBugs以生成QuixBugs-LE数据集。我们在QuixBugs-LE数据集上对Python和Java的评估突显了我们方法LecPrompt的令人印象深刻的能力。对于Python,LecPrompt实现了值得注意的74.58%的top-1 token级修复准确率和27.4%的程序级修复准确率。在Java中,LecPrompt提供了69.23%的top-1 token级修复准确率和24.7%的完整程序级修复准确率。
英文摘要:
Logical errors in programming don't raise compiler alerts, making them hard to detect. These silent errors can disrupt a program's function or cause run-time issues. Their correction requires deep insight into the program's logic, highlighting the importance of automated detection and repair. In this paper, we introduce LecPrompt to localize and repair logical errors, an prompt-based approach that harnesses the capabilities of CodeBERT, a transformer-based large language model trained on code. First, LecPrompt leverages a large language model to calculate perplexity and log probability metrics, pinpointing logical errors at both token and line levels. Through statistical analysis, it identifies tokens and lines that deviate significantly from the expected patterns recognized by large language models, marking them as potential error sources. Second, by framing the logical error correction challenge as a Masked Language Modeling (MLM) task, LecPrompt employs CodeBERT to autoregressively repair the identified error tokens. Finally, the soft-prompt method provides a novel solution in low-cost scenarios, ensuring that the model can be fine-tuned to the specific nuances of the logical error correction task without incurring high computational costs. To evaluate LecPrompt's performance, we created a method to introduce logical errors into correct code and applying this on QuixBugs to produce the QuixBugs-LE dataset. Our evaluations on the QuixBugs-LE dataset for both Python and Java highlight the impressive capabilities of our method, LecPrompt. For Python, LecPrompt achieves a noteworthy 74.58% top-1 token-level repair accuracy and 27.4% program-level repair accuracy. In Java, LecPrompt delivers a 69.23\% top-1 token-level repair accuracy and 24.7% full program-level repair accuracy.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。