Skip to main content
QUICK REVIEW

[论文解读] Think Outside the Code: Brainstorming Boosts Large Language Models in Code Generation

Xin-Ye Li, Jiang-Tian Xue|arXiv (Cornell University)|May 18, 2023
Software Engineering ResearchComputer Science被引用 3
一句话总结

本文提出 Brainstorm 框架,通过在代码实现前引入头脑风暴步骤以生成并筛选多样化的算法思路,从而提升大型语言模型(LLMs)在竞赛级代码生成中的表现。通过利用这些高层次的蓝图,该方法显著增强了推理能力,并在 CodeContests 上将 pass@k 指标提升超过 50%,在 LeetCode 上达到与人类程序员相当的性能。

ABSTRACT

Code generation aims to automatically generate source code from high-level task specifications, which can significantly increase productivity of software engineering. Recently, approaches based on large language models (LLMs) have shown remarkable code generation abilities on simple tasks. However, generate code for more complex tasks, such as competition-level problems, remains challenging. In this paper, we introduce Brainstorm framework for code generation. It leverages a brainstorming step that generates and selects diverse thoughts on the problem to facilitate algorithmic reasoning, where the thoughts are possible blueprint of solving the problem. We demonstrate that Brainstorm significantly enhances the ability of LLMs to solve competition-level programming problems, resulting in a more than 50% increase in the pass@$k$ metrics for ChatGPT on the CodeContests benchmark, achieving state-of-the-art performance. Furthermore, our experiments conducted on LeetCode contests show that our framework boosts the ability of ChatGPT to a level comparable to that of human programmers.

研究动机与目标

  • 解决使用大型语言模型生成复杂竞赛级编程问题正确代码的挑战。
  • 超越简单的提示到代码映射,提升 LLM 的算法推理能力。
  • 通过引入结构化的中间推理过程,减少对昂贵强化学习和大规模采样的依赖。
  • 评估生成并筛选多样化高层解决方案蓝图是否能提升代码生成性能。
  • 在 CodeContests 等基准测试和真实 LeetCode 竞赛中展示最先进性能。

提出的方法

  • 引入头脑风暴步骤,在代码生成前生成多个多样化、高层次的算法思路(解决方案蓝图)。
  • 使用神经排序模型根据问题描述和候选思路选择最具前景的思路。
  • 将选定的思路和问题规范输入代码生成模型(如 ChatGPT)以完成最终实现。
  • 在 CodeContests 和 APPS 等基准测试上端到端应用该框架,并通过 pass@k 指标进行评估。
  • 通过消融研究分析不同问题难度级别和标签下的性能表现。
  • 通过将生成的代码提交至 LeetCode 官方在线评测系统,验证结果的正确性。
Figure 1 : An illustrative example for the Brainstorm framework.
Figure 1 : An illustrative example for the Brainstorm framework.

实验结果

研究问题

  • RQ1生成并筛选多样化高层算法思路是否能显著提升 LLM 在竞赛级代码生成中的表现?
  • RQ2Brainstorm 框架是否能增强 LLM 的算法推理能力,特别是在涉及图论或动态规划等复杂问题上?
  • RQ3该框架在竞技编程中不同问题难度级别和标签下的表现如何?
  • RQ4该框架是否能在真实世界编码平台(如 LeetCode)上实现与人类程序员相当的性能?
  • RQ5为何该框架在简单问题上表现不佳,导致入门级任务的 pass@1 和 pass@5 指标下降?

主要发现

  • 在 CodeContests 基准测试中,Brainstorm 将 ChatGPT 的 pass@1 指标从 4.5% 提升至 7.0%,相对提升 55.1%。
  • pass@5 指标从 9.3% 提升至 14.7%,相对提升 58.5%;pass@100 从 18.2% 提升至 29.3%,相对提升 61.0%。
  • 在 APPS 基准测试中,Brainstorm 对竞赛级任务的 pass@1 和 pass@100 指标均实现超过 30% 的相对提升。
  • 在 LeetCode 竞赛中,Brainstorm 将 ChatGPT 的整体 pass@1 从 19.2% 提升至 40.3%,接近人类水平性能(72.2% pass@1)。
  • 该框架在涉及图论、最短路径和概率的问题上表现出最大的相对提升,表明其显著增强了算法推理能力。
  • 该框架在简单问题(如入门级和面试级任务)上表现较差,可能是因为直接生成比推理更高效。
Figure 3 : The overview for training thoughts ranker model.
Figure 3 : The overview for training thoughts ranker model.

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。