SIaM: Self-Improving Code-Assisted Mathematical Reasoning of Large Language Models

Dian Yu, Baolin Peng, Ye Tian, Linfeng Song, Haitao Mi, Dong Yu

TL;DR

SIaM (Self-Improving Code-Assisted Math) is a novel paradigm that boosts the mathematical reasoning of LLMs by leveraging large-scale, diverse, expert-written web data. By using a code-based critic model to filter and label self-generated solutions, the authors enable iterative self-improvement that significantly enhances generalization, allowing 7-8B parameter models to outperform state-of-the-art 70B models on out-of-domain benchmarks.

What Problem Does This Paper Address?

Large Language Models (LLMs) often stumble on math problems requiring precise multi-digit computation or complex logical steps. While "Chain-of-Thought" (CoT) reasoning helps, it is prone to "hallucinated" calculation errors. A popular fix is code-assisted reasoning—teaching models to write Python scripts that a computer then executes to find the answer.

However, current methods rely heavily on distilling knowledge from closed-source giants like GPT-4 using a few small, clean datasets like GSM8K. This creates two issues:

  1. Limited Diversity: Models overfit to specific question styles and fail to generalize to real-world, high-school, or college-level math.
  2. The Evaluation Gap: Real-world math data from the web is "messy." Answers come in various formats (LaTeX, multiple-choice labels, coordinates), making it hard for simple scripts to verify if a model's code execution result actually matches the reference answer.

Methods

The authors propose an iterative self-improvement loop centered around a code-based critic model.

Figure 1: Overview of our self-improving code-assisted paradigm using large-scale web QA data.

The process follows three main stages:

  1. Initial Training ($M_0$): A base model is fine-tuned on high-quality "seed" data ($D_0$) generated by GPT-4.
  2. Building the Critic: The authors train a specialized critic model to act as a judge. Given a question, a reference answer, and a candidate code solution's execution result, the critic predicts "YES" or "NO" regarding their alignment. This bypasses the need for complex, hand-written heuristic rules for every new dataset.
  3. Iterative Self-Improvement:
    • The current policy model generates multiple code samples for new, unseen web questions.
  4. The critic filters these samples, keeping only the best-performing ones.
  5. The model is updated via Supervised Fine-Tuning (SFT) and Direct Preference Optimization (DPO) using these self-generated "winning" and "losing" pairs.

Datasets

The study utilizes a mix of standard benchmarks and large-scale web resources:

  • Seed Data ($D_0$): GSM8K and MATH (English); 20K web-sourced questions (Chinese).
  • Value-Style Data ($D_1$): APE and CM datasets, where answers are simple numerical values.
  • Diverse-Format Data ($D_2$): Large-scale QA pairs from educational websites and the WebInstruct corpus. This includes multiple-choice, fill-in-the-blank, and proof-style questions.
Statistics of training data

Key Insights and Ideas

  • Code as a Universal Language: Interestingly, training on Chinese-only math data ($D_1$ and $D_2$) did not hurt English performance and sometimes even improved it. The authors suggest that because the logic is captured in Python code, the natural language of the comments matters less than the cross-lingual reasoning logic.
  • The Critic as an Evaluator: The critic model showed a high correlation (0.79 Kendall’s $\tau$) with traditional heuristic-based evaluation. This means the critic can be used to score models on new, complex benchmarks where writing evaluation rules would be too labor-intensive.
  • Length Control in DPO: Standard DPO often leads to "length exploitation," where models generate unnecessarily long responses to get higher scores. The authors found that adding an SFT loss term during DPO training was surprisingly effective at keeping code responses concise.

Key Results

The SIaM paradigm yielded impressive gains across the board:

  • Generalization: On the MathBench (a difficult out-of-domain benchmark), SIaM-improved 8B models achieved a 4.4% accuracy boost, outperforming the 70B parameter ToRA model by 11.9% in application-heavy scenarios.
  • In-Domain Gains: Models saw improvements of up to +5.7% on Chinese tasks and +3.7% on English GSM8K.
  • Robustness: The iterative approach consistently outperformed single-stage training, proving that the model can effectively learn from its own high-quality generations when guided by a strong critic.

Limitations and Future Work

  • Language Bias: The current critic model was trained primarily on Chinese data. While it generalized well to English, a more balanced multi-lingual critic could be even more effective.
  • Theoretical Reasoning: The authors note that while code is excellent for computation and practical problem-solving, it may be less suited for advanced theoretical reasoning that doesn't require calculation.
  • Scaling: The study focused on 7-8B parameter models due to resource constraints. Exploring how this paradigm scales to much larger models (e.g., 70B+) remains an open question.

Summary updated

BibTeX
@misc{yu2024siam,
  author = {Dian Yu and Baolin Peng and Ye Tian and Linfeng Song and Haitao Mi and Dong Yu},
  title = {{SIaM: Self-Improving Code-Assisted Mathematical Reasoning of Large Language Models}},
  year = {2024},
  eprint = {2408.15565},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2408.15565},
}
Figure