Embedding Self-Correction as an Inherent Ability in Large Language Models for Enhanced Mathematical Reasoning

Kuofeng Gao, Huanqia Cai, Qingyao Shuai, Dihong Gong, Zhifeng Li · Submission to ICLR 2025 · Rejected

TL;DR

Current open-source LLMs struggle with multi-step mathematical reasoning and typically lack the ability to autonomously detect and rectify their own errors. This paper introduces the Chain of Self-Correction (CoSC), a framework that trains language models to iteratively generate code, execute it with an interpreter, verify intermediate results, and self-correct across multiple rounds in a fully zero-shot manner. Using a cost-effective, two-phase distillation and self-enhancement pipeline, the resulting CoSC-Code-34B model achieves 53.5% on the challenging MATH benchmark, outperforming GPT-4 (CoT), GPT-4V, and Gemini-1.0 Ultra.

What Problem Does This Paper Address?

While large language models (LLMs) excel at natural language generation, rigorous mathematical reasoning remains a notorious hurdle. Mathematical problem-solving demands precise, multi-step logical deduction where a single arithmetic or conceptual bug early on cascades into complete failure.

Recent research has explored tool integration (like Python interpreters) or prompting strategies to prompt models to "reflect" or "self-correct." However, existing prompting approaches generally require heavy few-shot demonstrations, rely on proprietary closed-source APIs, or fail outright because smaller/open models lack the inherent capability to critique their own work. Meanwhile, supervised fine-tuning (SFT) methods usually focus on single-turn reasoning (e.g., standard Chain-of-Thought or Program-of-Thought), depriving models of the chance to learn how to recover when their initial attempt is flawed.

Methods

CoSC embeds iterative self-correction directly into the model’s weights via fine-tuning, structuring the inference trajectory into repeating cycles of Program $\to$ Output $\to$ Verification $\to$ Conclusion ($p \to o \to v \to c$):

  1. Program Generation ($p$): The model writes a Python function using symbolic libraries (e.g., SymPy) to solve the problem.
  2. Tool Execution ($o$): An external Python interpreter executes the code to return a runtime result or error trace.
  3. Structured Step-by-Step Verification ($v$): Instead of a generic critique, the model evaluates two explicit criteria:
  4. Step 1: Does the code logically and mathematically match the problem description and constraints?
  5. Step 2: Is the executed output plausible and compliant with the question requirements?
  6. Conclusion & Decision ($c$): The model assesses the verification. If consistent, it concludes with a boxed answer; if discrepancies or errors are found, it generates a revised program in the next round (capped at 3 tool calls).

To train this capability cheaply without generating millions of expensive GPT-4 calls, the authors design a two-phase training pipeline:

  • Phase 1 (CoSC Foundational Learning): Query GPT-4 with few-shot prompts to generate trajectories across MATH and GSM8K problems, keeping 37k valid samples where the final answer matches ground truth.
  • Phase 2 (CoSC Self-Enhancement): Use the Phase 1 seed model (CodeLLaMA-34B) to generate its own training data through dense solution sampling (sampling 64 times per training problem) and dense question sampling (using rephrased questions from MetaMATH). Correct trajectories yield 302k additional synthetic examples. Base models are then fine-tuned from scratch on all 339k trajectories.

Datasets

The authors evaluate and train on two primary benchmarks:

  • MATH: 12,500 challenging competition-level mathematics problems across 7 categories (Algebra, Precalculus, Number Theory, etc.), split into 7,500 train and 5,000 test problems.
  • GSM8K: 8,500 multi-step grade-school math word problems (7,500 train, 1,000 test).
  • MetaMATH (Data source only): Used during Phase 2 to source diverse, rephrased question formulations.

Key Insights and Ideas

  • Prompting alone does not yield reliable self-correction: Testing CoSC prompts on existing strong models like ToRA-Code-7B without fine-tuning caused performance to drop (from 44.6% down to 42.8% on MATH). The authors argue that models must learn self-correction as an internal behavioral pattern through weights, not just via instructions.
  • Verification must be disentangled: Prompting the model to separately verify the code against the problem statement and the execution result against expectations enables high-precision critique (achieving ~70% verification accuracy).
  • Self-correction successfully flips failure cases: On problems where the model initially generated an incorrect answer or encountered a runtime exception, the subsequent correction rounds resolved the error over 25% of the time.
  • Massive reduction in runtime bugs: On MATH with the 7B model, tool execution runtime errors (such as NotImplementedError) dropped from 931 to 167, and output inconsistency errors plummeted from 310 to just 1.

Key Results

Experiments evaluated LLaMA-2 and CodeLLaMA backbones across 7B, 13B, and 34B scales under zero-shot inference:

  • MATH Benchmark:
  • CoSC-Code-34B attained 53.5%, surpassing proprietary base models evaluated with few-shot CoT or PAL—including GPT-4 (42.5% CoT, 51.8% PAL), GPT-4V (52.9%), Claude-2 (32.5%), and Gemini-1.0 Ultra (53.2%).
  • CoSC-Code-7B reached 47.6%, beating previous 7B state-of-the-art ToRA-Code (44.6%) and WizardMath-7B (10.7%).
  • CoSC-Code-13B reached 50.3% (vs. ToRA-Code-13B's 48.1%).
  • GSM8K Benchmark:
  • CoSC-Code-34B achieved 82.3%, improving on ToRA-Code-34B (80.7%).
  • Multi-round Impact: Comparing single-round extraction against the iterative multi-round loop demonstrated a direct gain from 40.2% $\to$ 47.6% (7B) and 42.4% $\to$ 50.3% (13B) on MATH.

Limitations and Future Work

  • Domain Restriction: The framework was tested exclusively on mathematical problem-solving; the authors leave broader domains (e.g., general code synthesis, open-domain logical QA, science reasoning) to future study.
  • Reliance on Ground-Truth Filtering for Data Generation: Both foundational learning and self-enhancement rely on filtering trajectories against ground-truth labels, which limits self-enhancement to problems with known objective answers.
  • Interpreter Dependence: The method assumes problems can be translated into executable Python programs and requires an environment to run code, meaning non-algorithmic or conceptual theorem-proving problems remain difficult to verify.

Summary updated

BibTeX
@misc{gao2024embedding,
  author = {Kuofeng Gao and Huanqia Cai and Qingyao Shuai and Dihong Gong and Zhifeng Li},
  title = {{Embedding Self-Correction as an Inherent Ability in Large Language Models for Enhanced Mathematical Reasoning}},
  year = {2024},
  eprint = {2410.10735},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.10735},
}
Figure