Skip to main content
QUICK REVIEW

[论文解读] AceCoder: Utilizing Existing Code to Enhance Code Generation

Jia Li, Yunfei Zhao|arXiv (Cornell University)|Mar 31, 2023
Software Engineering Research被引用 16
一句话总结

AceCoder 将引导式代码生成和示例检索引入提示中,在 MBPP、MBJP 和 MBJSP 基准测试上显著提升多种大语言模型(LLM)和多种语言的代码生成准确性。

ABSTRACT

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.

研究动机与目标

  • 由于两个独特的挑战:需求理解和代码实现,推动对代码生成的专业提示的必要性。
  • 提出 AceCoder,包含两种机制——引导式代码生成和示例检索,以应对这些挑战。
  • 在多种 LLM 与编程语言上,利用公开基准和人工评测来证明有效性。
  • 提供消融和设计见解,以展示每个 AceCoder 模块的贡献。

提出的方法

  • 通过使用 Lucene 的 BM25 从语料库检索相似的 <requirement, code> 对。
  • 选择器通过通过 n-gram 覆盖和基于衰减的打分循环(Algorithm 1)来减少冗余,从而筛选检索到的示例。
  • 分析器将检索到的程序转换为 <requirement, preliminary, code> 三元组,方法是从示例中提取 preliminaries(如测试用例)。
  • 提示构建将三元组示例注入提示中,使 LLM 首先生成一个 preliminaries(例如测试用例),然后给出最终代码。
  • 三步代码生成:LLM 使用构建的提示输出一个 preliminaries,随后输出代码。
  • 在 MBPP(Python)、MBJP(Java)、MBJSP(JavaScript)上,对三种基础 LLM(CodeGeeX-13B、CodeGen-6B、InCoder-6B)进行 Pass@k 评估(k=1、3、5)。

实验结果

研究问题

  • RQ1RQ1:AceCoder 在代码生成方面是否比现有提示技术更准确?
  • RQ2RQ2:AceCoder 与基于检索的基线相比如何?
  • RQ3RQ3:人工开发者是否更偏好 AceCoder 生成的代码?
  • RQ4RQ4:AceCoder 三个模块(Retriever、Selector、Analyzer)各自的贡献是什么?
  • RQ5RQ5:哪种三模块设计选择能最大化性能?

主要发现

Base modelPromptingMBPP Pass@1MBPP Pass@3MBPP Pass@5MBJP Pass@1MBJP Pass@3MBJP Pass@5MBJSP Pass@1MBJSP Pass@3MBJSP Pass@5
CodeGeeX-13BZero-shot prompting5.2013.8019.404.4611.9718.260.200.200.41
CodeGeeX-13BCoT prompting12.6023.4030.2014.4028.1933.6711.3521.1025.96
CodeGeeX-13BFew-shot prompting20.4030.6036.0016.6326.1734.4811.1619.8825.56
CodeGeeX-13BAceCoder26.7436.4341.1328.3836.7941.5421.0331.4436.04
CodeGen-6BZero-shot prompting10.4019.4024.4014.8125.7631.448.7219.6722.92
CodeGen-6BCoT prompting13.0021.0026.0013.5925.3531.2411.5620.0824.54
CodeGen-6BFew-shot prompting14.6024.0030.2018.2530.0234.689.9419.8823.12
CodeGen-6BAceCoder22.8334.5840.1622.4534.2740.9616.4527.3132.16
InCoder-6BZero-shot prompting4.2011.4016.202.235.889.133.655.888.11
InCoder-6BCoT prompting3.9910.6515.311.834.467.101.222.034.67
InCoder-6BFew-shot prompting12.8022.8028.2010.9523.5326.1712.7822.5227.79
InCoder-6BAceCoder20.1631.4434.1016.3729.8934.7415.9727.1330.65
  • AceCoder 在 Pass@1 上对 MBPP 提升最高可达 56.4%、对 MBJP 提升最高可达 70.7%、对 MBJSP 提升最高可达 88.4%。
  • AceCoder 在 Pass@1 上相较于基于检索的基线,提升最高可达 13.1%(MBPP)、23.44%(MBJP)和 15.8%(MBJSP)。
  • AceCoder 的效果在从 6B 到 13B 的大语言模型规模,以及在 Python、Java 和 JavaScript 上都有所提升。
  • 人工评测显示开发者更倾向 AceCoder 生成的程序在正确性、代码异味和可维护性方面。
  • 消融研究表明三大模块(Retriever、Selector、Analyzer)均对性能提升做出贡献;设计变体也进行了对比。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。