Skip to content

Commit a02bb15

Browse files
Apply suggestions from code review
Co-authored-by: Clémentine Fourrier <[email protected]>
1 parent 2086fe7 commit a02bb15

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/lighteval/metrics/utils/extractive_match_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ def lazy_latex_regex(latex_config: LatexExtractionConfig, language: Language) ->
151151
r"("
152152
r"(?<!\\)\$\$(?P<latexDisplayDollar>[\s\S]+?)(?<!\\)\$\$|" # $$...$$ (display math, can be multiline)
153153
r"(?<!\\)\\\[(?P<latexDisplayBracket>[\s\S]+?)(?<!\\)\\\]|" # \[...\] (display math, can be multiline)
154-
r"(?<!\\|\d)\$(?P<latexInlineDollar>(?:\\[$]|[^\n$])+?)(?<!\\)\$|" # $...$ (inline math, single line, allows escaped $), we make sure it's not preceed by a digit to minimize false positives with actualy dollar unit
154+
r"(?<!\\|\d)\$(?P<latexInlineDollar>(?:\\[$]|[^\n$])+?)(?<!\\)\$|" # $...$ (inline math, single line, allows escaped $), we make sure it's not preceded by a digit to minimize false positives containing dollar as a unit
155155
r"(?<!\\)\\\((?P<latexInlineParenthesis>[^\n]+?)(?<!\\)\\\)|" # \(...\) (inline math, single line)
156-
r"(?<!\\)\[(?P<latexInlineBracket>[^\n$]+?)(?<!\\)\]" # [....] While this is no a valid display math llms like to generate it, allow it
156+
r"(?<!\\)\[(?P<latexInlineBracket>[^\n$]+?)(?<!\\)\]" # [....] While this is not a valid display, math LLMs like to generate it. We allow it
157157
rf"){percent_re_group}?"
158158
)
159159

@@ -306,7 +306,7 @@ def extract_expr(match: re.Match) -> tuple[str | sympy.Expr | None, str]:
306306
is_percentage = True if groups.get("percent", None) else False
307307

308308
if integer or decimal:
309-
# This makes sure we can convert numebrs like 0001 to 1, do note that this can convert 0 to ''
309+
# This makes sure we can convert numbers like 0001 to 1. Do note that this can convert 0 to '', so we assume an empty string was 0 and convert it back afterwards.
310310
integer = integer.translate(str.maketrans("", "", ", ")).lstrip("0")
311311
if len(integer) == 0:
312312
integer = "0"

src/lighteval/metrics/utils/math_comparisson.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ def sympy_expr_eq(gold: Basic | MatrixBase, pred: Basic | MatrixBase, precision:
336336
Returns:
337337
True if expressions are equal by any comparison method, False otherwise
338338
"""
339-
# If refernce is relational, but target it's not it's possible it's case of k=x+1+z, so we just take x+1+z
340-
# We assume that the gold never contains symplifications, so we don't handle that case
341-
# e.g 1+1+1=3 will never be simplified to 3, it would be possibly by doing lhs-rhs == 0, but ehhh just make the gold simpler
339+
# If the reference is relational, but the target is not, it's possible it's a case of answer=x+1+z, so we just take x+1+z
340+
# We assume that the gold never needs to be simplified, so we don't handle that case
341+
# e.g 1+1+1=3 will never be simplified to 3; it would be possible to do so with lhs-rhs == 0, but we assume the gold is at its most simplified form.
342342
# The new latex2sympy2 will actually convert such cases automatically, but so this is in theory not needed
343343
if isinstance(gold, Eq) and not isinstance(pred, Relational) and isinstance(gold.lhs, Symbol):
344344
gold = gold.rhs

0 commit comments

Comments
 (0)