Abstract
Large Language Models (LLMs) have advanced Natural Language Processing (NLP) tasks but are limited in mathematical reasoning. To address this, few-shot examples are used in prompts for in-context learning. However, existing methods require annotated datasets, resulting in higher computational costs and lower quality examples. To mitigate these limitations, we propose AutoMathIC, a framework that automatically generates high-quality in-context examples to enhance LLMs’ mathematical reasoning. AutoMathIC ensures consistency across different modalities (e.g., Chain-of-Thought (CoT), code snippets, and equations) by generating and selecting mutations that improve response consistency. Evaluated on four math problem datasets, AutoMathIC outperforms six baselines, with LLM accuracy ranging from 87.0% to 99.3% for GPT-3.5 and 93.1% to 98.7% for GPT-4o-mini. It surpasses the state-of-the-art in-context example retrieval method in three of the four datasets by 0.3% to 11.8%, without relying on an annotated dataset.
Introduction
While Large Language Models (LLMs) have revolutionized natural language processing, they frequently struggle with multi-step mathematical reasoning. The standard approach to improving performance is In-Context Learning (ICL), where the model is provided with a few solved examples (shots) within the prompt. However, current ICL methods face two major hurdles: a heavy dependency on large, manually annotated datasets for example retrieval, and the difficulty of ensuring the quality of automatically generated explanations. If a provided example contains a reasoning error, the LLM is likely to mimic that error.
To address these challenges, we introduce AutoMathIC, a framework designed to generate high-quality in-context examples on the fly. By specifically tailoring examples to the target problem without requiring human-labeled libraries, AutoMathIC provides a self-supervised path to enhanced mathematical reasoning.
The AutoMathIC Framework
The core of AutoMathIC is a two-stage pipeline: Target Question Mutation and Selection by Multi-Modal Consistency.
Target Question Mutation
The framework operates on the principle that changing the numerical values in a math problem while maintaining its structure preserves the underlying reasoning algorithm. AutoMathIC identifies numerical values in a target question and replaces them with random values of the same data type (integers or floats) to create a pool of "mutant" questions. This ensures that the generated examples are perfectly relevant to the logic required for the target question.
Multi-Modal Consistency
To ensure these generated examples are correct without ground-truth labels, AutoMathIC employs modality consistency. The LLM is prompted to solve mutated questions using three distinct reasoning paths:
- Chain-of-Thought (CoT): Natural language step-by-step reasoning.
- Code: A Python function that calculates the answer.
- Equation: A WolframAlpha-style mathematical expression.
If the LLM arrives at the same answer through all three methods, the explanation is considered highly reliable. This "agreement" serves as a powerful filter for quality, allowing the system to function in a fully self-supervised manner.
Iterative Optimization
AutoMathIC uses a selection algorithm to identify the best mutated examples. These are prepended to the target question, and the system checks if the LLM's consistency on the target question improves. If a new "shot" increases the model's confidence and consistency across modalities for the actual problem, the example is retained.
Experimental Results
AutoMathIC was evaluated on four arithmetic reasoning benchmarks: ASDiv (1,218 problems), SVAMP (1,000 problems), GSM8k (1,319 problems), and MultiArith (600 problems). Testing was conducted using GPT-3.5 and GPT-4o-mini.
As shown in the results, AutoMathIC consistently outperformed baselines, including state-of-the-art retrieval methods. On the SVAMP dataset, AutoMathIC improved GPT-3.5's accuracy from 79.5% (Zero-shot CoT) to 87.0%. Furthermore, it surpassed retrieval methods that rely on external data by 0.3% to 11.8% across three datasets. Manual inspection confirmed the high quality of the selected mutants, with accuracy ranging between 73.3% and 100%.
Conclusion
AutoMathIC demonstrates that multi-modal consistency is a robust proxy for truth in mathematical reasoning. By forcing LLMs to align textual reasoning with code and equations, the framework acts as an effective self-correction mechanism. While the current implementation increases computational cost due to multiple API calls, future work will focus on adaptive mutation mechanisms and extending these principles to broader reasoning tasks like symbolic logic and geometry.
Summary updated