Skip to main content
QUICK REVIEW

[论文解读] Code Generation with AlphaCodium: From Prompt Engineering to Flow Engineering

Tal Ridnik, Dedy Kredo|arXiv (Cornell University)|Jan 16, 2024
Software Engineering Research被引用 18
一句话总结

AlphaCodium 是一个以代码为中心、以测试驱动的多阶段流程,迭代生成并修正代码以通过输入-输出测试,在 CodeContests 上显著提升代码生成性能,跨模型(例如 GPT-4 验证通过率从 19% 提升到 44%)。

ABSTRACT

Code generation problems differ from common natural language problems - they require matching the exact syntax of the target language, identifying happy paths and edge cases, paying attention to numerous small details in the problem spec, and addressing other code-specific issues and requirements. Hence, many of the optimizations and tricks that have been successful in natural language generation may not be effective for code tasks. In this work, we propose a new approach to code generation by LLMs, which we call AlphaCodium - a test-based, multi-stage, code-oriented iterative flow, that improves the performances of LLMs on code problems. We tested AlphaCodium on a challenging code generation dataset called CodeContests, which includes competitive programming problems from platforms such as Codeforces. The proposed flow consistently and significantly improves results. On the validation set, for example, GPT-4 accuracy (pass@5) increased from 19% with a single well-designed direct prompt to 44% with the AlphaCodium flow. Many of the principles and best practices acquired in this work, we believe, are broadly applicable to general code generation tasks. Full implementation is available at: https://github.com/Codium-ai/AlphaCodium

研究动机与目标

  • 通过设计一个面向代码的迭代流程来弥合自然语言提示与代码生成需求的差距。
  • 利用预处理、问题反思和测试驱动的迭代来提高解题质量。
  • 通过生成 AI 生成的测试用例并使用测试锚点来引导迭代修复来增强鲁棒性。
  • 在包含公开和闭源模型的 CodeContests 上证明有效性,并与以往方法进行比较。

提出的方法

  • 引入 AlphaCodium,一个两阶段流程(自然语言的预处理,随后是迭代的代码生成与测试)。
  • 使用问题反思和公开测试推理将任务 grounding 到细节。
  • 生成 2–3 个候选解决方案并按正确性与鲁棒性进行排序。
  • 创建 6–8 个 AI 生成的测试用例以覆盖公开测试中不存在的边界情况;生成初始代码解,并在测试集上运行/修复。
  • 对公开测试进行迭代运行和修复,然后再对 AI 生成的测试进行修复,使用测试锚点来防止回归。
  • 采用面向代码的设计概念(YAML 结构输出、要点式语义推理、模块化代码、双重验证、渐进式决策、测试锚点)。
(a) The proposed AlphaCodium flow.
(a) The proposed AlphaCodium flow.

实验结果

研究问题

  • RQ1AlphaCodium 流程相对于直接提示在开放和封闭模型中的表现如何?
  • RQ2与 AlphaCode 和 CodeChain 等先前方法相比,面向代码的流程是否提高了 CodeContests 的鲁棒性和成功率?
  • RQ3与先前的代码生成系统相比,AlphaCodium 的计算效率如何?
  • RQ4提出的设计概念(YAML 输出、模块化代码、测试锚点)是否对代码生成任务具有广泛的帮助?

主要发现

  • AlphaCodium 在不同模型上持续提升 CodeContests 的性能(例如 GPT-4 验证通过率从 19% 提升到 44%)。
  • 该流程在显著减少大模型调用次数的情况下取得更优的结果,显示出更高的样本效率和较低的计算成本。
  • AlphaCodium 在公开报道的指标上优于 CodeChain 与 AlphaCode 等先前工作,同时使用通用模型且不需要大量微调。
  • 在 GPT-4 上,验证的 pass@5 相对直接提示提升约为 2.3 倍(从 19% 到 44%)。
  • 该方法在验证集和测试集以及开放源代码和闭源模型上都保持有效性。
(b) Illustrating the improvement from AlphaCodium.
(b) Illustrating the improvement from AlphaCodium.

更好的研究,从现在开始

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

无需绑定信用卡

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