Training and Evaluating Math-Specialized Language Models

    Learn how to develop math-specialized language models through continued pretraining, supervised fine-tuning, and reinforcement learning with verifiable feedback. This article covers data preparation, checkpoint management, common training pitfalls, reproducible evaluation, and deployment monitoring, with an emphasis on separating answer accuracy from reasoning quality.

    Training a math-specialized model means turning a general-purpose language model into a reasoning system that can calculate, construct proofs, and check its own work. Competition-level problems require more than a correct final answer: intermediate steps must be verifiable, symbolic transformations must remain consistent, and boundary conditions must not be overlooked.

    Conversational fine-tuning on general-purpose data alone can encourage a model to memorize familiar problem patterns while struggling with variations. A more reliable approach is to use high-quality mathematical data for continued pretraining, instruction data to establish solution formats, and automatically gradable feedback for reinforcement learning.

    The following workflow presents these stages in an engineering-oriented sequence, without depending on any particular model vendor.

    1. Define Capabilities and Evaluation Conditions First

    Mathematical ability spans at least four areas: numerical calculation, algebra and symbolic manipulation, geometric and combinatorial reasoning, and condition management in multistep proofs.

    Public competition benchmarks often use multiple-choice questions or final answers that support exact matching, making automated scoring practical. Three factors are essential when interpreting their results.

    Tool access. Does the evaluation allow calculators, code interpreters, or retrieval? With tools enabled, the score measures planning and tool use as well as reasoning. Without tools, it more closely reflects the model’s internal symbolic reasoning. These results are not directly comparable.

    Sampling and verification. Does the evaluation use multiple samples followed by voting, or a larger model to verify solution steps? Voting can improve accuracy, but it increases inference cost and does not establish the reliability of a single response.

    Training–test overlap. Do the training data and test problems come from overlapping sources? Online solutions and scanned study materials can easily introduce benchmark contamination. Formal reports should describe decontamination procedures, including exact or approximate deduplication of normalized problem statements and spot checks for training-set overlap among correctly solved test problems.

    For internal acceptance testing, maintain three fixed evaluation configurations:

    • Single-pass greedy decoding.
    • Multiple samples at a fixed temperature, reporting the mean and variance.
    • A strict configuration with tools disabled.

    Publishing only the highest score provides little guidance for subsequent development.

    2. Source and Clean the Training Data

    The value of continued pretraining depends primarily on the density of math-related tokens, not simply on total token count. Public web data includes textbooks, solutions, and papers, but also advertisements, incorrect solutions, and machine-translated material.

    A practical preparation pipeline includes the following steps.

    1. Topic filtering. Use classifiers, keywords, and layout features to identify documents with substantial mathematical notation or proof and solution structures. Overly strict filtering can discard word problems; loose filtering can admit large amounts of unrelated conversation.

    2. Quality scoring. Retain structurally complete text with coherent reasoning. Downweight pages that contain only final answers or whose solution steps contradict their answers.

    3. Language and notation normalization. Standardize textual representations of formulas. Incompatible markup for the same fraction, for example, can cause the model to treat formatting differences as semantic differences.

    4. Deduplication and decontamination. Apply both document-level and paragraph-level checks. Competition problems are often short and widely repeated, so document hashes alone are insufficient.

    5. Data mixing. Combine mathematical text, natural-language explanations, and computation-related code. Code can reinforce stepwise execution and consistent variable use, but too much may encourage the model to write programs instead of proofs. A common approach is to adjust the mixture by stage: increase mathematical density early, then restore more general-language data later to reduce catastrophic forgetting.

    Choose the token budget with both compute constraints and forgetting risk in mind. Too little continued pretraining may produce limited specialization; too much training with an extreme data mixture can noticeably degrade general instruction following.

    Use downstream math evaluations and spot checks of general capabilities together as early-stopping signals, rather than relying solely on pretraining loss.

    3. Maintain Three Training Checkpoints

    In practice, retain three sets of weights rather than only the final conversational model.

    Base Model

    Continue pretraining an existing code-oriented or general-purpose base model to improve its modeling of formulas, definitions, theorems, and worked solutions.

    Do not force the data into a conversational template at this stage, as that can compromise the coherence of long proofs. Match the initialization to the data: if programmatic solutions account for a large share of the corpus, a base model with stronger coding capabilities may require less training data.

    Instruction-Tuned Model

    Use problem–solution pairs for supervised fine-tuning. Solutions should include the given information, the objective, key transformations, and checks, without requiring a rigid conversational script.

    Cover proof problems, calculation tasks, multiple-choice questions, and open-ended problems. Include a proportion of examples that decline to provide an answer or identify insufficient conditions, so the model does not invent numerical results when information is missing.

    Use a learning rate lower than that typically used for general conversational fine-tuning to avoid overwriting the symbolic patterns learned during pretraining.

    Reinforcement-Learning Model

    When final answers can be checked automatically, use outcome rewards to reinforce successful solution trajectories. Where only process annotations are available, use step-level rewards or a process verifier.

    Rewards based only on the final answer can encourage skipped steps or guessed choices. Mitigations include:

    • Downweighting responses with clearly missing steps.
    • Applying format constraints to limit empty or uninformative text.
    • Adding simple consistency checks to the reward, such as substituting an answer back into an equation.

    Record the sampling temperature, number of samples, and KL constraint settings used during reinforcement learning. Without these details, reproducing a training run is difficult.

    Release all three checkpoints together, or at least retain them internally. The base model supports further pretraining, the instruction-tuned model supports direct problem solving, and the reinforcement-learning model enables comparisons of gains from outcome-based rewards.

    If the license permits commercial use, clearly document the weight licensing terms, data disclosures, and prohibited uses to reduce downstream misuse.

    4. Common Training Pitfalls

    Catastrophic Forgetting

    After math-focused continued pretraining, summarization, translation, and tool use may regress. Periodically test a set of general-purpose tasks. If degradation exceeds the chosen threshold, mix in general-purpose data or reduce the learning rate.

    Evaluation Leakage

    Using the same problems to train a reward model and conduct final testing can inflate scores. Keep reward-model training data, validation data, and final test data separate.

    Hallucinated Reasoning Steps

    A model may produce the right answer while citing a nonexistent theorem. Automated answer metrics will not detect this. Manually sample responses to measure the proportion with correct answers but incorrect reasoning, and include that measure in acceptance criteria rather than relying on accuracy alone.

    Length Limits and Truncation

    Competition proofs can be long. Insufficient context or generation limits may cause a model to present an answer prematurely. Set maximum generation lengths by problem type and report the truncation rate.

    Mixing Tool-Assisted and Tool-Free Results

    If the product uses a calculator by default, also report results with tools disabled. Otherwise, it is difficult to determine whether the model itself is improving.

    5. Build a Minimal Evaluation and Deployment Loop

    A practical development loop is:

    Small-scale data experiments → fixed evaluation scripts → full continued pretraining → instruction fine-tuning → reinforcement learning on automatically gradable problems → manual review of reasoning errors.

    Evaluation scripts should fix random seeds, decoding parameters, and answer-extraction rules. Use rules or controlled parsing for answer extraction rather than asking another large model to judge answers leniently. Otherwise, scores can drift with changes to the judging model.

    The following illustrative normalization function standardizes whitespace and alternative notation without broadening semantic acceptance:

    1. def normalize(ans: str) -> str:
    2. s = ans.strip().replace(" ", "")
    3. s = s.replace("\\dfrac", "\\frac")
    4. return s.lower()

    This illustrates the need to standardize representations before calculating accuracy. It does not replace mathematical equivalence checking.

    For fractions, radicals, and intervals, use a symbolic computation library to compare equivalence, and record the proportion of answers that cannot be parsed. Automatically marking parsing failures as wrong can underestimate performance; marking them as correct can overestimate it. A safer approach is to report an “unparseable” category separately and review those cases manually.

    At deployment, tailor behavior to the use case. Batch homework grading can prioritize accuracy and allow somewhat longer reasoning. Real-time question answering needs tighter latency limits, a shorter reasoning budget, and prompts for human review when confidence is low.

    Monitor accuracy by topic—such as algebra, geometry, and number theory—not just overall accuracy. Aggregate scores can conceal important weaknesses.

    6. Interpret Claims of Performance Near Larger General-Purpose Models

    With external tools disabled and no voting across samples, a medium-sized math-specialized model may approach a larger general-purpose model on an individual competition benchmark.

    Such a result usually indicates effective data mixing and training-objective alignment. It does not establish parity in reasoning across domains, long proofs, or unfamiliar problem types.

    When reading these claims, ask:

    • What are the parameter count and inference cost?
    • How was benchmark contamination addressed?
    • Was the score obtained from one response or multiple samples?
    • Were tools disabled?
    • Did general-purpose capabilities regress?

    Scores are meaningfully comparable only when these conditions are presented together.

    For enterprise and research teams, the reusable lesson is to treat mathematics as a specialization rather than simply applying a general conversational model to problem sets. Use continued pretraining to build the foundation, instruction fine-tuning to shape solution formats, and reinforcement learning to exploit verifiable rewards. Pair these stages with strict, reproducible, topic-level evaluation to prevent inflated performance claims.

    When using cloud training, object storage, experiment tracking, and monitoring alerts, associate the data version, hyperparameters, and evaluation scripts with the same experiment record. This supports reliable comparisons across iterations without tying the workflow to a particular model brand.