Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/lighteval/metrics/normalizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ def _last_boxed_only_string(text: str) -> str | None:
return retval

def _fix_fracs(text: str) -> str:
"""
Fix the formatting of fractions in the given text.
Copied from: https://github.com/hendrycks/math/blob/357963a7f5501a6c1708cf3f3fb0cdf525642761/modeling/math_equivalence.py#L1

Args:
text (str): The input text.

Returns:
str: The text with properly formatted fractions.

Examples:
>>> _fix_fracs("\\frac12")
"\\frac{1}{2}"
>>> _fix_fracs("\\frac{3}{4}")
"\\frac{3}{4}"
>>> _fix_fracs("\\frac1{2}")
"\\frac{1}{2}"
"""
substrs = text.split("\\frac")
new_str = substrs[0]
if len(substrs) > 1:
Expand All @@ -149,7 +167,8 @@ def _fix_fracs(text: str) -> str:
assert len(substr) >= 2
except AssertionError:
return text
a, b = substr
a = substr[0]
b = substr[1]
if b != "{":
if len(substr) > 2:
post_substr = substr[2:]
Expand Down