Skip to content

Commit 75383d3

Browse files
committed
allow more separators
1 parent 33701c2 commit 75383d3

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ multilingual = [
109109
"jieba", # for chinese tokenizer
110110
"pyvi", # for vietnamese tokenizer
111111
]
112-
math = ["latex2sympy2_extended==1.0.5"]
112+
math = ["latex2sympy2_extended==1.0.6"]
113113

114114
[project.urls]
115115
Homepage = "https://github.com/huggingface/lighteval"

src/lighteval/metrics/utils/extractive_match_utils.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from typing import Any, Literal, Sequence
2828

2929
import sympy
30-
from sympy import Basic, FiniteSet, MatrixBase, Number
30+
from sympy import FiniteSet, Number
3131
from sympy.parsing import parse_expr
3232

3333
from lighteval.metrics.utils.math_comparison import should_treat_as_complex
@@ -234,7 +234,7 @@ def lazy_latex_regex(latex_config: LatexExtractionConfig, language: Language) ->
234234
and_word = translation_literal.and_word
235235
or_word = translation_literal.or_word
236236
next_groups = "".join(
237-
[rf"(?:\s*(?:{and_word}|{or_word})\s*{make_latex_env_pattern(f'next{i}_')})?" for i in range(1, 6)]
237+
[rf"(?:\s*(?:{and_word}|{or_word}|,)\s*{make_latex_env_pattern(f'next{i}_')})?" for i in range(1, 6)]
238238
)
239239

240240
latex_envs_re = rf"(?:{first_latex_group}{next_groups})"
@@ -266,7 +266,7 @@ def lazy_latex_regex(latex_config: LatexExtractionConfig, language: Language) ->
266266
latex_re_boxed = make_latex_env_pattern(prefix="first_", context="boxed")
267267
next_groups = "".join(
268268
[
269-
rf"(?:\s*(?:{and_word}|{or_word})\s*{make_latex_env_pattern(f'next{i}_', context='boxed')})?"
269+
rf"(?:\s*(?:{and_word}|{or_word}|,)\s*{make_latex_env_pattern(f'next{i}_', context='boxed')})?"
270270
for i in range(1, 6)
271271
]
272272
)
@@ -487,9 +487,7 @@ def extract_latex(
487487
return latex_exprs[0], latex_strs[0]
488488

489489

490-
def extract_match(
491-
match: re.Match, target_type: ExtractionTarget, timeout_seconds: int
492-
):
490+
def extract_match(match: re.Match, target_type: ExtractionTarget, timeout_seconds: int):
493491
"""Extracts the match from the regex match.
494492
495493
Args:

tests/metrics/test_extractive_match.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ def test_math_extraction_additional_cases(gold, pred, expected):
10351035
),
10361036
(
10371037
r"$(2,1),(1,2),(-1,-20),(-20,-1)$",
1038-
r"solutions are:\n\n\\[\n\\boxed{(1, 2)}, \\boxed{(2, 1)}, \\boxed{(-1, -20)}, \\boxed{(-20, -1)}\n\\]",
1038+
"solutions are:\n\n\\[\n\\boxed{(1, 2)}, \\boxed{(2, 1)}, \\boxed{(-1, -20)}, \\boxed{(-20, -1)}\n\\]",
10391039
1,
10401040
),
10411041
(
@@ -1121,6 +1121,16 @@ def test_math_extraction_additional_cases(gold, pred, expected):
11211121
r"$\boxed{10^{\frac{\sqrt{13} - 5}{6}}} \quad \text{and} \quad \boxed{10^{-\frac{5 + \sqrt{13}}{6}}}$",
11221122
1,
11231123
),
1124+
(
1125+
r"\boxed{1} and and and or thus but \boxed{2} and \boxed{3}",
1126+
r"$\boxed{2,3}$",
1127+
1,
1128+
),
1129+
(
1130+
r"\boxed{1} and and and or thus but \boxed{2} and \boxed{3}",
1131+
r"$\boxed{1,2,3}$",
1132+
0,
1133+
),
11241134
],
11251135
)
11261136
def test_math_numina_cases(gold, pred, expected):

0 commit comments

Comments
 (0)