huggingface / huggingface/Math-Verify

Enhance percentage handling to accept raw numbers without % symbol

Open
#67 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
1.2k
Forks
60
PR merge metrics
No merged PRs in 30d

Description

Description:
Currently, the verification system correctly handles:

"$28\\%$" vs "28 percent" → True (word forms work)

"$28\\%$" vs "28" → False (strict % symbol required)

We should modify the behavior so that:

"$28\\%$" vs "28" → True (treat raw numbers as percentages)

While maintaining existing support for word forms ("percent", "percentage", etc.)

Example Code:

```python

from math_verify import parse, verify, LatexExtractionConfig, ExprExtractionConfig

# https://huggingface.co/datasets/t-tech/T-math
def accuracy_reward(latex1: str, latex2: str, strict: bool = True) -> bool:
"""
Compare two LaTeX expressions for semantic equivalence, normalizing both before comparison.

Args:
latex1 (str): First LaTeX expression.
latex2 (str): Second LaTeX expression.
strict (bool): Whether to enforce strict variable matching (default: True).

Returns:
bool: True if the expressions are semantically equivalent, False otherwise.
"""
# Ensure both inputs are treated as LaTeX
def ensure_latex(s):
s = s.strip()
if not (s.startswith("$") and s.endswith("$")):
return f"${s}$"
return s

extraction_configs = [LatexExtractionConfig(), ExprExtractionConfig()]
parsed1 = parse(ensure_latex(latex1), extraction_configs)
parsed2 = parse(ensure_latex(latex2), extraction_configs)
return verify(parsed1, parsed2, strict=strict)

accuracy_reward("$28\\%$", "28 percentage")
accuracy_reward("$28\\%$", "28")
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.