Skip to content

Commit

Permalink
fix math parser
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanHB committed Oct 22, 2024
1 parent 2df94ff commit ce116ae
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lm_eval/tasks/leaderboard/math/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)


INVALID_ANSWER = "[invalidanswer]"


# taken from
# https://github.com/wellecks/lm-evaluation-harness/blob/master/lm_eval/tasks/minerva_math.py
def doc_to_text(doc: dict) -> str:
Expand Down Expand Up @@ -70,7 +73,7 @@ def process_results(doc: dict, results: List[str]) -> Dict[str, int]:
unnormalized_answer = get_unnormalized_answer(candidates)
answer = normalize_final_answer(unnormalized_answer)

if answer == "[invalidanswer]":
if answer == INVALID_ANSWER:
return {"exact_match": 0}

if answer.strip() == doc["answer"].strip() or is_equiv(answer, doc["answer"]):
Expand Down Expand Up @@ -125,11 +128,9 @@ def remove_boxed(s: str) -> str:

assert s[: len(left)] == left
assert s[-1] == "}"
return s[len(left) : -1]
except AssertionError:
print(s)
return s

return s[len(left) : -1]
return INVALID_ANSWER


class timeout:
Expand Down Expand Up @@ -192,7 +193,6 @@ def is_equiv(x1: str, x2: str) -> bool:


def get_unnormalized_answer(text: str) -> str:
INVALID_ANSWER = "[invalidanswer]"
end_seq = "I hope it is correct."
text += end_seq
match = re.search(
Expand Down

0 comments on commit ce116ae

Please sign in to comment.