Data Engineering and Reasoning Evaluation for Open-Source Math-Specialized Models

    This article explains why mathematical reasoning needs specialized models, then covers continued pretraining from a code base, a four-round data pipeline, a three-stage training path (base, instruction, RL), evaluation beyond accuracy, tool-use with sandbox execution, and practical deployment and licensing checks.

    Why mathematical reasoning needs specialized models

    Mathematical reasoning differs from general text generation: answers must be fluent, but they also need accurate symbolic operations, verifiable steps, and reproducible calculations. General-purpose large models are strong at natural language understanding, yet they often fail on multi-step algebra, geometric constraints, number-theoretic constructions, and combinatorial counting. A typical failure mode is “intermediate steps look plausible, final answer is wrong.” That usually comes from a missing closed loop among data distribution, training objectives, and evaluation protocol—not from a single missing skill.

    Public materials describe a math-specialized path of “code-capable base + math continued pretraining + instruction tuning + reinforcement learning,” explored at about 7 billion parameters. Three points matter. First, initializing from a code-pretrained model transfers structured symbols, control flow, and function-call patterns to formula rewriting, programmatic solving, and proof sketches. Second, continued pretraining on large-scale math-related tokens adapts the model to mixed distributions of math web pages, textbook-style language, solution text, and code snippets. Third, instruction tuning and RL turn “can solve problems” into “answer step by step, call tools when needed, and correct from execution results.”

    Without external toolkits and without multi-answer voting, the ~7B base version reports about 51.7% accuracy on public contest-level math reasoning benchmarks; an RL version with tool assistance approaches 60%. The technical takeaway is that a smaller specialized model can approach contemporaneous general models on math if data engineering and training stages are designed well. For production, accuracy alone is not enough: review evaluation protocol, data contamination, answer extraction rules, tool-call boundaries, and license constraints.

    Continued pretraining: from a code base to math corpora

    The series initializes from a code-pretrained model and continues pretraining on math-related tokens, natural language, and code for about 500 billion tokens. The goal is not simply “more math problems,” but a rebalanced mix so the model jointly learns: (1) natural-language problem understanding, (2) mathematical symbol and formula pattern recognition, and (3) programmatic solving and verification.

    Code pretraining helps in four ways. Variables, expressions, bracket matching, and type constraints resemble structured math formulas. Function calls and branches support strategies such as case analysis, auxiliary constructions, and iterative approximation. Program execution provides verifiable signals for later RL or tool collaboration. Comments, docs, and tests improve adaptation to “step explanation + result check” formats.

    Context length also matters. The public version uses a 4096-token sequence length, so long solutions, multi-round repairs, and tool returns must be truncated or summarized. In practice, compress “problem, key constraints, attempted steps, tool-output summary” into the window so critical constraints are not dropped.

    Data engineering: four iterations of high-quality math corpora

    The ceiling of a math-specialized model is largely set by data engineering. The public four-round loop can be abstracted as seed training, retrieval expansion, statistical identification, human annotation, then expansion again:

    1. Train a lightweight text classifier on an initial math-web seed set to judge math relevance.
    2. Deduplicate public web corpora, then retrieve candidate math pages with the classifier.
    3. Use statistics to identify high-frequency math domains, site structures, and link patterns.
    4. Manually annotate relevant URLs and add linked, previously uncollected pages to the seed set.
    5. Repeat four times, yielding tens of millions of math pages and about 120 billion tokens.

    The point is not “crawl more,” but controllable coverage and quality. Quality control should include deduplication and template filtering, language identification, formula density and code-block ratios, completeness of solutions, alignment of answers with explanations, low-quality Q&A filtering, sensitive-content filtering, and contamination checks against evaluation sets. For math data, especially keep the triple “stem—solution—answer” intact; do not keep answers without reasoning.

    Three-stage model path: base, instruction, and RL

    The series includes a base model, an instruction-tuned model, and an RL model. The base model learns language modeling and math patterns. Instruction tuning uses solutions, step-by-step reasoning, and formatted answers so the model answers in steps. RL (for example group-relative policy optimization) compares answer quality across samples, reinforcing correct paths and suppressing skipped steps and pseudo-reasoning.

    RL needs verifiable rewards. Math problems naturally support them: final answers can be matched, programs can be executed, formal proofs can be checked. Rewards can be split into outcome, process, and tool-use. Outcome rewards require a correct answer; process rewards encourage readable intermediate derivation; tool-use rewards encourage calling programs for heavy calculation, enumeration, and symbolic simplification instead of mental arithmetic. Poor reward design can cause over-reliance on tools or overly long traces, so apply length penalties, tool-call caps, and failed-retry policies.

    Evaluation protocol: engineering metrics beyond accuracy

    Math evaluation should not rest on a single accuracy number. Cover at least: few-shot chain-of-thought reasoning, zero-shot direct answering, tool collaboration, formal theorem proving, whether NLU and coding ability degraded, stability after long-context truncation, accuracy of answer-equivalence checks, and tool-call success rate plus average rounds.

    Public materials state that the base version, with few-shot CoT prompts, exceeds existing open-source base models by more than 10 percentage points in absolute accuracy, and the RL version with tools approaches 60%. Engineering evaluation should also check contamination (overlap of stems, solutions, or answers with the training corpus), whether answer extraction depends on a fixed template, whether multi-answer voting is disabled, and whether tool outputs were human-edited. Accuracy is comparable only when the protocol is transparent.

    Tool collaboration: write a program, execute, and verify

    A key capability is tool use. For large-number arithmetic, equation solving, enumeration, symbolic simplification, matrix ops, and formal proof, the model can draft a program, run it in a sandbox, write results back into context, then explain. Pseudocode:

    1. def solve_math(problem):
    2. prompt = build_cot_prompt(problem, exemplars=4)
    3. draft = generate(model, tokenizer, prompt,
    4. max_new_tokens=1024, temperature=0.0)
    5. if need_tool(draft):
    6. code = extract_code_block(draft)
    7. result = sandbox_exec(code, timeout=5)
    8. repair_prompt = build_refine_prompt(problem, draft, result)
    9. draft = generate(model, tokenizer, repair_prompt,
    10. max_new_tokens=1024, temperature=0.0)
    11. return normalize_answer(draft)

    Engineering essentials include sandbox isolation, timeouts, resource limits, no network access, output truncation, exception handling, a cap on tool calls, and summarization of execution results. For formal proofs, map natural-language steps to formal statements and verify with a proof checker; on failure, fall back to a natural-language explanation and do not treat unverified proofs as correct.

    Deployment advice and compliance

    When deploying a math-specialized model, pin model and tokenizer versions, record training-data sources and licenses, check commercial-use terms, and keep an evaluation regression suite. On the inference side, use containers, object storage, logging, and monitoring to quota request length, concurrency, timeouts, and sandbox resources. For education, finance, or research, add human review, answer provenance, and risk notices; do not treat model output as a final conclusion.

    Overall, the value of open-source math-specialized models is not only “small size, high score,” but a systematic combination of data engineering, continued pretraining, instruction tuning, RL, and tool use. When reproducing or selecting a model, inspect data quality, evaluation protocol, tool sandbox, and licenses first, then run small regression tests on your own problem mix so math reasoning becomes reliable engineering capability.