Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Clémentine Fourrier <[email protected]>
  • Loading branch information
hynky1999 and clefourrier authored Jan 13, 2025
1 parent 2086fe7 commit a02bb15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/lighteval/metrics/utils/extractive_match_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def lazy_latex_regex(latex_config: LatexExtractionConfig, language: Language) ->
r"("
r"(?<!\\)\$\$(?P<latexDisplayDollar>[\s\S]+?)(?<!\\)\$\$|" # $$...$$ (display math, can be multiline)
r"(?<!\\)\\\[(?P<latexDisplayBracket>[\s\S]+?)(?<!\\)\\\]|" # \[...\] (display math, can be multiline)
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
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
r"(?<!\\)\\\((?P<latexInlineParenthesis>[^\n]+?)(?<!\\)\\\)|" # \(...\) (inline math, single line)
r"(?<!\\)\[(?P<latexInlineBracket>[^\n$]+?)(?<!\\)\]" # [....] While this is no a valid display math llms like to generate it, allow it
r"(?<!\\)\[(?P<latexInlineBracket>[^\n$]+?)(?<!\\)\]" # [....] While this is not a valid display, math LLMs like to generate it. We allow it
rf"){percent_re_group}?"
)

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

if integer or decimal:
# This makes sure we can convert numebrs like 0001 to 1, do note that this can convert 0 to ''
# 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.
integer = integer.translate(str.maketrans("", "", ", ")).lstrip("0")
if len(integer) == 0:
integer = "0"
Expand Down
6 changes: 3 additions & 3 deletions src/lighteval/metrics/utils/math_comparisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ def sympy_expr_eq(gold: Basic | MatrixBase, pred: Basic | MatrixBase, precision:
Returns:
True if expressions are equal by any comparison method, False otherwise
"""
# 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
# We assume that the gold never contains symplifications, so we don't handle that case
# 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
# 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
# We assume that the gold never needs to be simplified, so we don't handle that case
# 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.
# The new latex2sympy2 will actually convert such cases automatically, but so this is in theory not needed
if isinstance(gold, Eq) and not isinstance(pred, Relational) and isinstance(gold.lhs, Symbol):
gold = gold.rhs
Expand Down

0 comments on commit a02bb15

Please sign in to comment.