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

利用编译器反馈迭代细化项目级代码上下文以实现精确代码生成

Iterative Refinement of Project-Level Code Context for Precise Code Generation with Compiler Feedback

Huazhong University of Science and Technology(华中科技大学);University of Leeds(利兹大学);Chongqing University(重庆大学);Shanghai Jiao Tong University(上海交通大学)

Zhangqian Bi, Yao Wan, Zheng Wang, Hongyu Zhang, Batu Guan, Fangxin Lu, Zili Zhang, Yulei Sui, Hai Jin, Xuanhua Shi

AI总结:

本文提出CoCoGen方法,通过编译器反馈和静态分析迭代修复LLM生成代码中的项目上下文不匹配问题,在Python代码生成中将GPT-3.5-Turbo和Code Llama的性能提升超过80%,并优于现有检索式基线。

摘要:

大型语言模型(LLMs)在自动化代码生成方面已取得显著进展。然而,LLM生成的代码可能在API使用、类、数据结构方面存在错误,或缺失项目特定信息。由于大量项目特定上下文无法放入LLM的提示中,我们必须寻找方法让模型能够探索项目级代码上下文。我们提出CoCoGen,一种利用编译器反馈改进LLM生成代码的新代码生成方法。CoCoGen首先利用静态分析识别生成代码与项目上下文之间的不匹配。然后,它利用从代码仓库中提取的信息迭代地对齐并修复所识别的错误。我们将CoCoGen与两个代表性LLM集成,即GPT-3.5-Turbo和Code Llama(13B),并将其应用于Python代码生成。实验结果表明,CoCoGen在生成依赖项目上下文的代码方面将原始LLM的性能显著提升了超过80%,并一致优于现有的基于检索的代码生成基线。

英文摘要:

Large Language Models (LLMs) have shown remarkable progress in automated code generation. Yet, LLM-generated code may contain errors in API usage, class, data structure, or missing project-specific information. As much of this project-specific context cannot fit into the prompts of LLMs, we must find ways to allow the model to explore the project-level code context. We present CoCoGen, a new code generation approach that uses compiler feedback to improve the LLM-generated code. CoCoGen first leverages static analysis to identify mismatches between the generated code and the project's context. It then iteratively aligns and fixes the identified errors using information extracted from the code repository. We integrate CoCoGen with two representative LLMs, i.e., GPT-3.5-Turbo and Code Llama (13B), and apply it to Python code generation. Experimental results show that CoCoGen significantly improves the vanilla LLMs by over 80% in generating code dependent on the project context and consistently outperforms the existing retrieval-based code generation baselines.

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

↑