arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.13932cs.SEcs.AI
收藏

针对LLM生成代码可靠性提升的定向验证问题链

Chain of Targeted Verification Questions to Improve the Reliability of Code Generated by LLMs

Polytechnique Montréal(蒙特利尔理工学院)

Sylvain Kouemo Ngassom, Arghavan Moradi Dakhel, Florian Tambon, Foutse Khomh

AI总结:

本研究提出一种基于针对性验证问题链的自我精炼方法,通过分析代码AST节点识别并修复LLM生成代码中的潜在错误,无需测试用例,在CoderEval上减少21%-62%错误并提升13%可执行性。

摘要:

基于LLM的助手,如GitHub Copilot和ChatGPT,有潜力生成满足自然语言描述(称为提示)的编程任务的代码。这些助手的广泛可访问性使得具有不同背景的用户能够生成代码并将其集成到软件项目中。然而,研究表明,LLM生成的代码容易出错,可能遗漏任务规范中的各种边界情况。向用户展示此类有缺陷的代码可能影响他们对基于LLM的助手的可靠性和信任。此外,用户需要付出大量努力来检测和修复代码中存在的任何错误,尤其是在没有测试用例的情况下。在本研究中,我们提出了一种自我精炼方法,旨在通过在执行前最小化错误数量来提高LLM生成代码的可靠性,无需人工干预,且在没有测试用例的情况下。我们的方法基于有针对性的验证问题(VQs)来识别初始代码中的潜在错误。这些VQs针对初始代码的抽象语法树(AST)中的各个节点,这些节点有可能触发LLM生成代码中常见的特定类型的错误模式。最后,我们的方法通过使用有针对性的VQs和初始代码重新提示LLM来尝试修复这些潜在错误。我们基于CoderEval数据集中的编程任务的评估表明,我们提出的方法优于最先进的方法,将代码中的目标错误数量减少了21%至62%,并将可执行代码实例的数量提高了13%。

英文摘要:

LLM-based assistants, such as GitHub Copilot and ChatGPT, have the potential to generate code that fulfills a programming task described in a natural language description, referred to as a prompt. The widespread accessibility of these assistants enables users with diverse backgrounds to generate code and integrate it into software projects. However, studies show that code generated by LLMs is prone to bugs and may miss various corner cases in task specifications. Presenting such buggy code to users can impact their reliability and trust in LLM-based assistants. Moreover, significant efforts are required by the user to detect and repair any bug present in the code, especially if no test cases are available. In this study, we propose a self-refinement method aimed at improving the reliability of code generated by LLMs by minimizing the number of bugs before execution, without human intervention, and in the absence of test cases. Our approach is based on targeted Verification Questions (VQs) to identify potential bugs within the initial code. These VQs target various nodes within the Abstract Syntax Tree (AST) of the initial code, which have the potential to trigger specific types of bug patterns commonly found in LLM-generated code. Finally, our method attempts to repair these potential bugs by re-prompting the LLM with the targeted VQs and the initial code. Our evaluation, based on programming tasks in the CoderEval dataset, demonstrates that our proposed method outperforms state-of-the-art methods by decreasing the number of targeted errors in the code between 21% to 62% and improving the number of executable code instances to 13%.

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

↑