Skip to main content
QUICK REVIEW

[Paper 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 Science3 citations
TL;DR

This paper proposes Brainstorm, a framework that enhances large language models (LLMs) for competition-level code generation by introducing a brainstorming step to generate and select diverse algorithmic thoughts before code implementation. By leveraging these high-level blueprints, the method boosts reasoning and improves pass@k metrics by over 50% on CodeContests, achieving performance comparable to human programmers on 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.

Motivation & Objective

  • To address the challenge of generating correct code for complex, competition-level programming problems using large language models.
  • To improve the algorithmic reasoning capabilities of LLMs beyond simple prompt-to-code mapping.
  • To reduce reliance on costly reinforcement learning and large-scale sampling by introducing structured intermediate reasoning.
  • To evaluate whether generating and selecting diverse high-level solution blueprints enhances code generation performance.
  • To demonstrate state-of-the-art performance on benchmarks like CodeContests and real-world LeetCode contests.

Proposed method

  • Introduce a brainstorming step that generates multiple diverse, high-level algorithmic thoughts (solution blueprints) before code generation.
  • Use a neural ranker model to select the most promising thought based on problem description and candidate thoughts.
  • Feed the selected thought and problem specification to a code generation model (e.g., ChatGPT) for final implementation.
  • Apply the framework end-to-end on benchmarks such as CodeContests and APPS, with evaluation via pass@k metrics.
  • Conduct ablation studies to analyze performance across problem difficulty levels and tags.
  • Validate results on LeetCode by submitting generated code to the official online judge for correctness.
Figure 1 : An illustrative example for the Brainstorm framework.
Figure 1 : An illustrative example for the Brainstorm framework.

Experimental results

Research questions

  • RQ1Can generating and selecting diverse high-level algorithmic thoughts significantly improve LLMs' performance on competition-level code generation?
  • RQ2Does the Brainstorm framework enhance algorithmic reasoning in LLMs, especially for complex problems like those involving graphs or dynamic programming?
  • RQ3How does the framework perform across different problem difficulty levels and tags in competitive programming?
  • RQ4Can the framework achieve performance comparable to human programmers on real-world coding platforms like LeetCode?
  • RQ5Why does the framework underperform on simple problems, and what causes the drop in pass@1 and pass@5 for introductory tasks?

Key findings

  • Brainstorm increases the pass@1 metric for ChatGPT on the CodeContests benchmark from 4.5% to 7.0%, a 55.1% relative improvement.
  • The pass@5 metric improves from 9.3% to 14.7%, a 58.5% relative increase, and pass@100 from 18.2% to 29.3%, a 61.0% relative improvement.
  • On the APPS benchmark, Brainstorm achieves over 30% relative improvement in pass@1 and pass@100 for competition-level tasks.
  • On LeetCode contests, Brainstorm boosts ChatGPT’s overall pass@1 from 19.2% to 40.3%, approaching human performance (72.2% pass@1).
  • The framework shows the largest relative improvement on problems involving graphs, shortest paths, and probabilities, indicating enhanced algorithmic reasoning.
  • The framework underperforms on simple problems (e.g., introductory and interview-level tasks), likely because direct generation is more efficient than reasoning for such cases.
Figure 3 : The overview for training thoughts ranker model.
Figure 3 : The overview for training thoughts ranker model.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.