arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2409.00676cs.SE
收藏

修复基础大语言模型的函数级代码生成错误

Fixing Function-Level Code Generation Errors for Foundation Large Language Models

Hao Wen, Yueheng Zhu, Chao Liu, Xiaoxue Ren, Weiwei Du, Meng Yan

AI总结:

该研究通过实证分析14个大模型在HumanEval数据集上的12837个代码生成错误,归纳出19类成因,提出三步修复方法LlmFix,可有效提升函数级代码生成准确率。

摘要:

函数级代码生成利用基础大语言模型(LLM)自动生成具备预期功能的源代码,已在GitHub Copilot等智能编程助手中得到广泛研究与应用,以提升软件开发效率。尽管基础LLM取得了进展,但生成过程仍存在大量错误。现有研究利用静态分析工具(如TBar)或新增一个修复用LLM(即LDB)对这些错误进行后处理,但由于尚未探究错误的根本原因,仍有许多错误有待解决,这给设计更优的修复工具带来了挑战。\n本文首先针对生成错误开展了实证研究。具体而言,我们在HumanEval数据集上复现了14个具有代表性的LLM并验证其正确性,共获取12837个代码生成错误,并对错误成因进行了分析,归纳出19类错误原因。实证分析表明其中三类成因的错误可被直接修复。基于上述发现,我们提出了名为LlmFix的修复方法,通过三步流程处理这三类错误:过滤代码以修正缩进、截断冗余的生成代码、导入缺失的模块。\n我们从两个角度对LlmFix进行了评估:其在错误修复任务上的性能,以及对函数级代码生成任务的提升效果。在错误修复性能方面,我们构建了评估数据集LlmErrorEval。实验结果显示,LlmFix的修复率达到17.1%,优于表现最佳的LDB 8.9个百分点。在代码生成提升方面,LlmFix在HumanEval和MBPP数据集上的评估均证明了其有效性,在14个LLM上平均提升了7.5%的代码生成准确率。

英文摘要:

Function-level code generation leverages foundation Large Language Models (LLMs) to automatically produce source code with expected functionality. It has been widely investigated and applied in intelligent programming assistants, such as GitHub Copilot, to enhance software development productivity. Despite advancements in foundation LLMs, the generation involves many errors. Existing studies leverage static analysis tools (e.g., TBar) or add another fixing LLM (i.e., LDB) to post-process these errors. However, there are still many errors remaining to be solved because their root causes have not been investigated yet, making it challenging to design better fixing tools. In this paper, we first conducted an empirical study on the generation errors. Specifically, we reproduced 14 representative LLMs on the HumanEval dataset and verified their correctness. We obtained 12,837 code generation errors and conducted an analysis of their causes, leading to 19 categories of error causes. Our empirical analysis indicated that three of these causes can be directly fixed. Based on the findings, we proposed a fixing method called LlmFix, which addresses these three types of errors through a three-step process: filtering code for indentation correction, truncating redundant generated code, and importing missing modules. Evaluations of LlmFix are conducted from two perspectives: its performance on error-fixing tasks and its impact on improving function-level code generation tasks. For error fixing performance, we built an evaluation dataset LlmErrorEval. Experimental results show that LlmFix achieves a fix rate of 17.1% outperforming the best LDB by 8.9%. For code generation improvements, evaluations of LlmFix on both the HumanEval and MBPP datasets demonstrate its effectiveness, improving code generation accuracy by an average of 7.5% across 14 LLMs.

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

↑