MathPrompter: Mathematical Reasoning using Large Language Models

Shima Imani, Liang Du, Harsh Shrivastava

TL;DR

This paper introduces MathPrompter, a novel technique to improve the mathematical reasoning capabilities of Large Language Models (LLMs). By generating multiple algebraic and Pythonic solutions to a problem and verifying their consensus, MathPrompter significantly boosts accuracy and builds user trust, achieving state-of-the-art results on the MultiArith dataset.

What Problem Does This Paper Address?

Large Language Models (LLMs) have shown remarkable progress in natural language understanding, but they often struggle with mathematical reasoning tasks. Unlike natural language, math problems typically have a single correct answer, making errors more apparent and problematic. This lack of accuracy, coupled with LLMs' inability to express confidence in their answers, creates a trust deficit that hinders their adoption for critical applications. Existing "chain-of-thought" (CoT) prompting methods, while improving reasoning, often lack mechanisms to validate intermediate steps or quantify confidence, leaving users uncertain about the reliability of the generated solutions.

Methods

MathPrompter tackles this challenge by mimicking how humans approach complex problems: breaking them down and verifying solutions through multiple perspectives. The core of MathPrompter involves a four-step process:

  1. Generating Algebraic Template: The original math problem (Q) is first converted into a generalized algebraic expression (Qt) by replacing numerical values with variables. A key-value mapping stores the original numbers.
  2. Math-Prompts: The LLM is prompted to generate multiple analytical solutions for Qt. This includes generating an algebraic expression and a Python function that can solve the problem. The idea is to get different "views" of the solution.
  3. Compute Verification: The generated algebraic and Pythonic solutions are then evaluated. This is done by substituting multiple randomized sets of values for the variables in Qt and comparing the outputs. The Python eval() method is used for computation.
  4. Statistical Significance: To ensure reliability, the process of generating and verifying solutions (steps II and III) is repeated multiple times (N ≈ 5). The most frequent answer among these iterations is considered the final solution. This consensus-building mechanism increases confidence in the result. If consensus isn't reached, the process is repeated.

Datasets

The primary dataset used for evaluation is MultiArith (Roy and Roth, 2016), a collection of mathematical reasoning problems designed to test complex arithmetic operations and logical reasoning. It's a subset of the Math World Problem Repository. The paper does not introduce any new datasets.

Key Insights and Ideas

  • Mimicking Human Reasoning: The core insight is that by emulating human strategies of breaking down problems and cross-verifying solutions, LLMs can achieve higher accuracy in mathematical reasoning.
  • Multiple Representations for Robustness: Generating both algebraic expressions and Python functions for the same problem provides diverse analytical paths. If these diverse paths converge on the same answer, it significantly increases confidence in its correctness.
  • Consensus as a Confidence Indicator: The statistical significance step, where multiple runs and checks are performed, acts as an implicit confidence score. A strong consensus across multiple attempts suggests a more reliable answer.
  • Addressing the Trust Deficit: By providing a more robust and verifiable solution generation process, MathPrompter aims to build user trust in LLM outputs for mathematical tasks.

Key Results

MathPrompter achieved a significant improvement in accuracy on the MultiArith dataset, increasing it from 78.7% to 92.5%. This performance is comparable to state-of-the-art few-shot CoT models and even larger models with 540B parameters, while MathPrompter itself uses a 175B parameter GPT-based LLM. The paper also highlights through example comparisons that MathPrompter can avoid common errors made by other models, such as unnecessary steps or misinterpretations of problem constraints.

Limitations and Future Work

The authors acknowledge that while MathPrompter increases accuracy and reliability, it does not guarantee correctness. There can be instances where both algebraic and Pythonic expressions, even when in agreement, produce erroneous results (as shown in the last row of Table 2). They suggest that increasing the number of prompts or employing additional techniques could further mitigate this issue. Future work includes evaluating MathPrompter on additional datasets and exploring more sophisticated prompting strategies.

Summary updated

BibTeX
@inproceedings{imani2023mathprompter,
  author = {Shima Imani and Liang Du and Harsh Shrivastava},
  title = {{MathPrompter: Mathematical Reasoning using Large Language Models}},
  booktitle = {RTML @ ICLR},
  year = {2023},
  url = {https://openreview.net/forum?id=BVo-P3SyoDL},
}
Figure