CodePlan: Unlocking Reasoning Potential in Large Langauge Models by Scaling Code-form Planning

Jiaxin Wen, Jian Guan, Hongning Wang, Wei Wu, Minlie HuangarXiv 2024 · DOI

Abstract

Large Language Models (LLMs) frequently struggle with complex, multi-step reasoning tasks, often losing logical coherence. This paper introduces CODEPLAN, a framework that scales reasoning potential by teaching LLMs to generate structured, Python-style pseudocode "blueprints" before producing a final natural language answer. By leveraging the inherent logic of programming constructs like loops and conditionals, CODEPLAN achieves a 25.1% average performance boost across 13 benchmarks with minimal computational overhead.

Introduction

Despite their fluency, LLMs face a significant bottleneck in high-level planning. When tackling multi-hop question answering or intricate mathematical problems, models often jump to premature conclusions or produce repetitive, unstructured responses. This limitation stems from the nature of standard pre-training data, which typically captures final arguments rather than the underlying step-by-step logical frameworks used to derive them. While techniques like Chain-of-Thought (CoT) or task-specific fine-tuning offer some relief, they can be brittle or fail to generalize. CODEPLAN addresses this by providing a universal, structured language for planning: pseudocode.

The CODEPLAN Framework

CODEPLAN decomposes the generation process into two distinct stages:

  1. Planning: The model generates a high-level logical blueprint in pseudocode.
  2. Surface Realization: The model follows the generated plan to produce the final natural language response.

Unlike natural language plans, which can be ambiguous, pseudocode forces the model to be explicit about control flow. Programming constructs such as if/else for conditional logic, for loops for iteration, and functions for sub-task decomposition provide a robust scaffolding for complex reasoning.

Comparison of reasoning approaches: CodePlan uses structured pseudocode to guide the final response, avoiding common pitfalls in base and standard models.

To train models in this paradigm, the authors utilized a teacher model (Llama-3-8B-Instruct) to synthesize pseudocode plans for 2 million prompt-response pairs from the WebInstruct dataset. Smaller models, including Mistral-7B and Llama-2 variants, were then fine-tuned on these <Prompt, Code-Plan, Response> triplets.

Experimental Setup

The framework was evaluated across 13 diverse benchmarks covering mathematical reasoning (GSM8K, MATH), symbolic reasoning (Boolean Expression, Dyck Language), instruction-following (AlpacaEval, MT-Bench), and multi-hop QA (HotpotQA, MuSiQue).

Key Results and Insights

CODEPLAN demonstrated substantial improvements over vanilla training and existing baselines like "Plan-and-Solve" or "Quiet-STaR."

Performance Scaling with Complexity

A critical finding is that CODEPLAN's benefits scale with task difficulty. On the MuSiQue multi-hop QA dataset, the relative improvement over vanilla models increased from 6.3% on 2-hop questions to 43.8% on 4-hop questions. This suggests that structured planning becomes increasingly indispensable as the logical depth of a problem grows.

Performance comparison across multi-hop reasoning tasks. CodePlan demonstrates superior scaling as task complexity increases from 2-hop to 4-hop questions.

Efficiency and Generalization

Despite the two-stage process, CODEPLAN is highly efficient. The concise nature of pseudocode results in only a ~5% increase in inference time and no additional memory overhead. Furthermore, the use of functions allows models to abstract common operations into reusable mental "blocks," enhancing data efficiency and generalization across domains.

Conclusion

CODEPLAN effectively unlocks the latent reasoning capabilities of LLMs by bridging the gap between unstructured text and formal logic. By scaling code-form planning, the framework provides a robust, interpretable, and efficient path toward more capable AI agents. Future work will explore multi-path planning, self-refinement of code plans, and integration with external APIs for interactive decision-making.

Summary updated

BibTeX
@misc{wen2024codeplan,
  author = {Jiaxin Wen and Jian Guan and Hongning Wang and Wei Wu and Minlie Huang},
  title = {{CodePlan: Unlocking Reasoning Potential in Large Langauge Models by Scaling Code-form Planning}},
  year = {2024},
  eprint = {2409.12452},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.12452},
}
Figure