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

AceCoder:利用现有代码增强代码生成

AceCoder: Utilizing Existing Code to Enhance Code Generation

Peking University(北京大学)

Jia Li, Yunfei Zhao, Yongmin Li, Ge Li, Zhi Jin

AI总结:

针对LLM代码生成需求理解与实现难题,提出AceCoder提示技术,通过引导代码生成与示例检索机制,显著提升多语言、多规模模型在基准测试中的Pass@k表现及人类偏好。

摘要:

大型语言模型(LLMs)在代码生成方面取得了巨大成功。LLMs将提示作为输入并输出代码。一个关键问题是如何制作提示(即提示技术)。现有的提示技术是为自然语言生成而设计的,在代码生成中的准确率较低。在本文中,我们提出了一种名为AceCoder的新提示技术。我们的动机是代码生成面临两个独特的挑战(即需求理解和代码实现)。AceCoder包含两个新颖的机制(即引导代码生成和示例检索)来解决这些挑战。(1)引导代码生成要求LLMs首先分析需求并输出中间初步结果(例如,测试用例)。该初步结果用于澄清需求并告诉LLMs“写什么”。(2)示例检索选择相似的程序作为提示中的示例,这些示例提供了大量相关内容(例如,算法、API)并教LLMs“怎么写”。我们将AceCoder应用于三个LLMs(例如,Codex),并使用Pass@k在三个公共基准上进行评估。结果表明,AceCoder可以显著提高LLMs在代码生成上的性能。(1)在Pass@1方面,AceCoder在MBPP中比最先进的基线高出56.4%,在MBJP中高出70.7%,在MBJSP中高出88.4%。(2)AceCoder在不同规模(即6B到13B)和不同语言(即Python、Java和JavaScript)的LLMs中均有效。(3)人类评估表明人类开发者更喜欢来自AceCoder的程序。

英文摘要:

Large Language Models (LLMs) have shown great success in code generation. LLMs take as the input a prompt and output the code. A key question is how to make prompts (i.e., Prompting Techniques). Existing prompting techniques are designed for natural language generation and have low accuracy in code generation. In this paper, we propose a new prompting technique named AceCoder. Our motivation is that code generation meets two unique challenges (i.e., requirement understanding and code implementation). AceCoder contains two novel mechanisms (i.e., guided code generation and example retrieval) to solve these challenges. (1) Guided code generation asks LLMs first to analyze requirements and output an intermediate preliminary (e.g., test cases). The preliminary is used to clarify requirements and tell LLMs "what to write". (2) Example retrieval selects similar programs as examples in prompts, which provide lots of relevant content (e.g., algorithms, APIs) and teach LLMs "how to write". We apply AceCoder to three LLMs (e.g., Codex) and evaluate it on three public benchmarks using the Pass@k. Results show that AceCoder can significantly improve the performance of LLMs on code generation. (1) In terms of Pass@1, AceCoder outperforms the state-of-the-art baseline by up to 56.4% in MBPP, 70.7% in MBJP, and 88.4% in MBJSP. (2) AceCoder is effective in LLMs with different sizes (i.e., 6B to 13B) and different languages (i.e., Python, Java, and JavaScript). (3) Human evaluation shows human developers prefer programs from AceCoder.

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

↑