Implementation:Open compass VLMEvalKit MEGABench LaTeX Expr Equality
| Field | Value |
|---|---|
| source | VLMEvalKit |
| domain | Vision, Evaluation, Mathematics, LaTeX Parsing |
Overview
Determines equality between LaTeX mathematical expressions using symbolic parsing for the MEGA-Bench evaluation framework.
Description
The `LatexExprEquality` class provides a `match` method that normalizes and parses two LaTeX expression strings using sympy's `parse_latex`, then checks symbolic equality. It includes a configurable timeout (default 15 seconds) using signal-based alarm to prevent hanging on complex expressions. On parsing failure (LaTeXParsingError, SympifyError, TypeError), it falls back to `SimpleStrMatch` for direct string comparison. The `separate_text_and_latex` helper splits mixed text-and-LaTeX content for individual comparison.
Usage
Called internally by the corresponding dataset class during evaluation.
Code Reference
- Source:
vlmeval/dataset/utils/megabench/scoring/latex_expr_equality.py, Lines: L1-96 - Import:
from vlmeval.dataset.utils.megabench.scoring.latex_expr_equality import LatexExprEquality
Key Functions:
class LatexExprEquality:
@classmethod
def match(cls, responses, targets, timeout_duration=15) -> int: ...
def separate_text_and_latex(text): ...
I/O Contract
| Direction | Description |
|---|---|
| Inputs | Two LaTeX expression strings for comparison |
| Outputs | Integer 1 (equal) or 0 (not equal) |
Usage Examples
from vlmeval.dataset.utils.megabench.scoring.latex_expr_equality import LatexExprEquality
score = LatexExprEquality.match("\\frac{1}{2}", "0.5")