Skip to content

Commit c744bdf

Browse files
authored
[MATH] Fix MATH normalization (#162)
1 parent 1c04946 commit c744bdf

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/lighteval/metrics/normalizations.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,24 @@ def _last_boxed_only_string(text: str) -> str | None:
136136
return retval
137137

138138
def _fix_fracs(text: str) -> str:
139+
"""
140+
Fix the formatting of fractions in the given text.
141+
Copied from: https://github.com/hendrycks/math/blob/357963a7f5501a6c1708cf3f3fb0cdf525642761/modeling/math_equivalence.py#L1
142+
143+
Args:
144+
text (str): The input text.
145+
146+
Returns:
147+
str: The text with properly formatted fractions.
148+
149+
Examples:
150+
>>> _fix_fracs("\\frac12")
151+
"\\frac{1}{2}"
152+
>>> _fix_fracs("\\frac{3}{4}")
153+
"\\frac{3}{4}"
154+
>>> _fix_fracs("\\frac1{2}")
155+
"\\frac{1}{2}"
156+
"""
139157
substrs = text.split("\\frac")
140158
new_str = substrs[0]
141159
if len(substrs) > 1:
@@ -149,7 +167,8 @@ def _fix_fracs(text: str) -> str:
149167
assert len(substr) >= 2
150168
except AssertionError:
151169
return text
152-
a, b = substr
170+
a = substr[0]
171+
b = substr[1]
153172
if b != "{":
154173
if len(substr) > 2:
155174
post_substr = substr[2:]

0 commit comments

Comments
 (0)