Skip to content

Enhance percentage handling to accept raw numbers without % symbol #67

@ArtiomNosov

Description

@ArtiomNosov

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:

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")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions