Math-Verify is a robust Python library from HuggingFace, currently at version 0.9.0, designed for evaluating Large Language Model outputs in mathematical tasks. It provides sophisticated capabilities for parsing and verifying mathematical expressions, including LaTeX and plain numerical formats. The library supports complex features like set theory, equation/inequality comparison, and advanced normalization, aiming to offer higher accuracy in assessing LLM performance on math problems by moving beyond strict format requirements and inflexible comparison logic. It maintains an active development and release cadence.
pip install math-verifyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `parse` to extract mathematical expressions from strings (both LaTeX and plain expressions) and `verify` to check for mathematical equivalence. It highlights the use of `ExtractionConfig` classes and illustrates the default asymmetric behavior for comparing intervals and inequalities.
Review any code that explicitly creates or manipulates `sympy.FiniteSet` objects intended for use with `math-verify`. Consider adapting to `latex2sympy2_extended.sets.FiniteSet` or ensuring compatibility through conversion if necessary.
Remove the `equations` parameter from your `NormalizationConfig` instances. The parser will automatically manage equation handling.
If symmetric comparison is desired, pass `allow_set_relation_comp=True` to the `verify` function. For example: `verify(gold, answer, allow_set_relation_comp=True)`.
Monitor parsing times for very long or complex inputs. Adjust the overall `parsing_timeout` parameter in your `ExtractionConfig` or consider pre-processing excessively long inputs if timeouts become frequent.
To ensure internal errors are propagated as exceptions, set `raise_on_error=True` when calling `parse` or `verify`. Alternatively, configure your Python logging to display messages at `DEBUG` level for the `math_verify` module.
Always use the `parse` function to process both gold and prediction answers before passing their outputs to `verify`. Avoid manually creating mixed lists of SymPy objects and strings for direct verification.
Install the package using pip: `pip install math-verify`.
Check the module's documentation for the correct function name and update the import statement accordingly.
Ensure that the inputs to the function are correct and that the function is used as per the library's guidelines.
Change your import statement to `from math_verify import parse, verify` to directly import the functions.
Ensure mathematical expressions are correctly formatted. For LaTeX, make sure expressions are enclosed in supported environments like `\boxed{...}`, `$$...$$`, or `\[...\]`.