TL;DR
This paper tackles the challenge of teaching Large Language Models (LLMs) to perform mathematical reasoning using specialized tools like SMT solvers. They introduce a novel method for generating synthetic training data by leveraging the SMT grammar, which significantly improves LLMs' ability to generate correct code for solving complex counting problems.
What Problem Does This Paper Address?
LLMs are increasingly being used for mathematical reasoning by offloading complex tasks to external tools (like SymPy). However, this approach is limited by the availability of training data for these tools. Many specialized tools, particularly those for combinatorial problems, lack sufficient high-quality training data, leading to poor performance even in state-of-the-art LLMs. This paper focuses on improving LLM performance with Satisfiability Modulo Theories (SMT) solvers, specifically the Z3Py API, which is powerful for counting problems but underrepresented in LLM training data.
Methods
The core contribution is a method for generating synthetic training data for LLMs to interact with Z3Py. This involves:
- Synthetic Problem Generation: Creating problem statements and corresponding Z3Py solutions from scratch. They define four classes of ground sets (sequences, permutations, numbers in base k, subsets) and associated constraints.
- Rephrasing: To make the synthetic problems sound more natural and less prone to LLM overfitting on specific formats, they use a language model to rephrase the problems and generate new Z3Py solutions. This rephrasing process includes a verification step to ensure the rephrased problem and its solution yield the same answer as the original.
- Problem Filtering: They also leverage existing datasets (NuminaMath) by filtering for enumeration problems solvable by Z3Py, generating multiple Z3Py solutions for each problem using LLMs, and then using rejection sampling.
Datasets
- Synthetic Datasets: The authors generated two types of synthetic datasets:
- Directly generated synthetic problems and Z3Py solutions.
- Rephrased synthetic problems with corresponding Z3Py solutions.
- NuminaMath Dataset: Used for filtering and creating a baseline training set of real-world mathematical problems. They specifically filtered for enumeration problems solvable by Z3Py.
Key Insights and Ideas
- Synthetic Data is Powerful: The paper demonstrates that even fully synthetic, randomly generated problems can be highly effective for training LLMs on specialized reasoning tasks, especially when real-world data is scarce.
- Rephrasing Mitigates Overfitting: Simply fine-tuning on raw synthetic data can lead to LLMs overfitting to the specific problem formats. Rephrasing the problems with a language model helps create more robust models that generalize better.
- Z3Py is a Promising Tool: Despite its lower popularity compared to tools like SymPy, Z3Py is shown to be a powerful tool for counting problems, and LLMs can be effectively trained to use it.
- Fine-tuning Enhances General Reasoning: Fine-tuning LLMs on Z3Py-based problems not only improves their ability to generate Z3Py code but also enhances their overall mathematical problem-solving capabilities, even for tasks not directly related to Z3Py.
Key Results
- Improved Z3Py Encoding: Fine-tuning LLMs on the generated synthetic dataset significantly enhances their ability to generate accurate Z3 constraint encodings.
- Enhanced Problem Solving: Models fine-tuned on synthetic data outperform their baseline counterparts, solving problems they previously could not, even when allowed to use arbitrary libraries.
- Quantitative Performance: The paper presents a pass@k metric evaluation. For GPT-40, fine-tuning on a mix of synthetic and NuminaMath data achieved a score of 62, significantly higher than the baseline GPT-40 score of 45. For GPT-40-mini, fine-tuning on synthetic data yielded the best performance with a score of 49, outperforming the baseline of 29.
- Qualitative Improvements: Fine-tuned models were able to solve additional tasks that were previously unsolvable.
Limitations and Future Work
- Limitations:
- The paper acknowledges that even state-of-the-art LLMs are not yet proficient users of Z3Py without fine-tuning.
- The rephrasing process, while helpful, still relies on LLMs and can introduce its own set of potential issues if not carefully verified.
- Future Work:
- Developing more advanced synthetic problem statement generation techniques.
- Using fine-tuned models to bootstrap harder datasets from existing problem statements.
- Applying the synthetic data generation approach to other less well-known libraries for mathematical reasoning beyond Z3Py.
Summary updated