Overview
MathRubric extends Rubric to provide mathematical equivalence checking using the math_verify library. It evaluates whether model-generated mathematical answers are equivalent to ground truth, handling symbolic expressions, algebraic equivalence, and numerical precision.
Constructor
list[RewardFunc] | None
default:"None"
Additional reward functions beyond the built-in
correct_answer function.list[float] | None
default:"None"
Weights for additional reward functions. The built-in
correct_answer gets weight 1.0.Parser | None
default:"None"
Parser for extracting answers. Defaults to
MaybeThinkParser(extract_fn=extract_boxed_answer).int
default:"50"
Maximum number of thread pool workers for parallel verification.
float
default:"5"
Per-verification timeout in seconds. Returns 0.0 reward if exceeded.
Built-in Reward Function
correct_answer
Parser
Parser instance (automatically provided by the rubric).
Messages
Model’s completion to verify.
str
Ground truth answer in LaTeX format (will be wrapped in
\boxed{}).float - 1.0 if mathematically equivalent, 0.0 otherwise.
The function automatically wraps answers in
\boxed{} format before verification.Timeouts
MathRubric implements two-level timeout protection:
float
default:"5"
Soft timeout: Returns 0.0 if verification takes longer than this, but logs it as debug.
float
default:"120"
Hard timeout: Absolute maximum time for verification. Logs a warning if exceeded.
Attributes
ThreadPoolExecutor
Thread pool for running blocking
math_verify operations asynchronously.Example Usage
Basic Math Verification
Custom Parser for Boxed Answers
Adding Additional Metrics
Custom Timeout Settings
Combining with Other Reward Functions
Handling Edge Cases
Mathematical Equivalence
Themath_verify library checks various forms of equivalence:
- Symbolic:
2x + 6≡2(x + 3) - Numerical:
0.333...≡1/3 - Algebraic:
(x+1)^2≡x^2 + 2x + 1 - Trigonometric:
sin^2(x) + cos^2(x)≡1
Performance Considerations
Verification runs in a thread pool executor to avoid blocking the async event loop.
Notes
- Empty or unparseable responses always receive 0.0 reward
- Timeout violations are logged at debug level for soft timeouts, warning for hard timeouts
- The rubric suppresses
math_verifylibrary timeout warnings (handled internally) - All parsing exceptions return 0.0 rather than raising errors
See Also
- Rubric - Base rubric class
- JudgeRubric - LLM-based scoring
- MaybeThinkParser - Parser for thinking and answer extraction