(model_output: str, ground_truth: str)
| 380 | |
| 381 | import math |
| 382 | def evaluate_math(model_output: str, ground_truth: str) -> bool: |
| 383 | model_output = str(model_output) |
| 384 | ground_truth = str(ground_truth) |
| 385 | |
| 386 | is_matched, extracted_model_output = match_answer(model_output) |
| 387 | format_correctness = "Step 2:" in model_output and "\\box" in model_output |
| 388 | # print(f"{model_output=}") |
| 389 | # print("\n") |
| 390 | # print(f"{extracted_model_output=}") |
| 391 | # print("\n") |
| 392 | # print(f"{ground_truth=}") |
| 393 | # print("="*20) |
| 394 | # print("\n\n") |
| 395 | |
| 396 | # grade simple algebra questions. if succeed, return; otherwise, proceed to more complex grading |
| 397 | if grade_answer(extracted_model_output, ground_truth): |
| 398 | return True, True, extracted_model_output |
| 399 | # return True |
| 400 | |
| 401 | try: |
| 402 | if "\pi" in extracted_model_output or "\pi" in ground_truth: |
| 403 | equivs = [] |
| 404 | for pi in [math.pi, 3.14]: |
| 405 | equivs.append(math_equal(extracted_model_output, ground_truth, timeout=True, pi=pi)) |
| 406 | is_correct = any(equivs) |
| 407 | else: |
| 408 | is_correct = math_equal(extracted_model_output, ground_truth, timeout=True) |
| 409 | except: |
| 410 | is_correct = False |
| 411 | |
| 412 | # print(f"{extracted_model_output=}\n", f"{model_output=}\n", f"{ground_truth=}\n") |
| 413 | |
| 414 | return is_correct, format_correctness, extracted_model_output |
| 415 | |
| 416 | |
| 417 |
nothing calls this directly
no test coverage detected