MCPcopy Create free account
hub / github.com/LeapLabTHU/Absolute-Zero-Reasoner / parse_ground_truth

Function parse_ground_truth

evaluation/math_eval/eval/parser.py:536–618  ·  view source on GitHub ↗
(example: Dict[str, Any], data_name)

Source from the content-addressed store, hash-verified

534
535
536def parse_ground_truth(example: Dict[str, Any], data_name):
537 if "gt_cot" in example and "gt" in example:
538 if data_name in ["math"]:
539 gt_ans = extract_answer(example["gt_cot"], data_name)
540 elif data_name in STRIP_EXCEPTIONS:
541 gt_ans = example["gt"]
542 else:
543 gt_ans = strip_string(example["gt"])
544 return example["gt_cot"], gt_ans
545
546 # parse ground truth
547 if data_name in ["math", "minerva_math", "math500"]: #关键代码
548 gt_cot = example["solution"]
549 gt_ans = extract_answer(gt_cot, data_name)
550 elif data_name == "gsm8k":
551 gt_cot, gt_ans = example["answer"].split("####")
552 elif data_name == "svamp":
553 gt_cot, gt_ans = example["Equation"], example["Answer"]
554 elif data_name == "asdiv":
555 gt_cot = example["formula"]
556 gt_ans = re.sub(r"\(.*?\)", "", example["answer"])
557 elif data_name == "mawps":
558 gt_cot, gt_ans = None, example["target"]
559 elif data_name == "tabmwp":
560 gt_cot = example["solution"]
561 gt_ans = example["answer"]
562 if example["ans_type"] in ["integer_number", "decimal_number"]:
563 if "/" in gt_ans:
564 gt_ans = int(gt_ans.split("/")[0]) / int(gt_ans.split("/")[1])
565 elif "," in gt_ans:
566 gt_ans = float(gt_ans.replace(",", ""))
567 elif "%" in gt_ans:
568 gt_ans = float(gt_ans.split("%")[0]) / 100
569 else:
570 gt_ans = float(gt_ans)
571 elif data_name == "carp_en":
572 gt_cot, gt_ans = example["steps"], example["answer"]
573 elif data_name == "mmlu_stem":
574 abcd = "ABCD"
575 gt_cot, gt_ans = None, abcd[example["answer"]]
576 elif data_name == "sat_math":
577 gt_cot, gt_ans = None, example["Answer"]
578 elif data_name == "aqua":
579 gt_cot, gt_ans = None, example["correct"]
580 elif data_name in ["gaokao2023en", "college_math", "gaokao_math_cloze"]:
581 gt_cot, gt_ans = None, example["answer"].replace("$", "").strip()
582 elif data_name == "gaokao_math_qa":
583 gt_cot, gt_ans = None, example["label"]
584 elif data_name in ["gaokao2024_mix", "cn_middle_school"]:
585 if len(example["choice_answer"]) > 0:
586 gt_cot, gt_ans = None, example["choice_answer"]
587 else:
588 gt_cot, gt_ans = None, example["answer"]
589 elif data_name == "olympiadbench":
590 gt_cot, gt_ans = None, example["final_answer"][0].strip("$")
591 elif data_name in [
592 "aime24",
593 "aime25",

Callers 3

parse_questionFunction · 0.85
mainFunction · 0.85
evaluateFunction · 0.85

Calls 2

extract_answerFunction · 0.70
strip_stringFunction · 0.70

Tested by

no test coverage detected