File size: 1,888 Bytes
e4a9b52 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | """Helpers for scoring Misraj/MathVision_testmini with mm_scoring.py.
prepare_mathvision(row) -> dict of the extra fields mm_scoring.py needs
(question_type, answer_type, choices, answer_is_letter, precision, ...)
final_prompt(ex) -> the dataset `prompt` plus a short answer-format instruction
"""
import re
def prepare_mathvision(row):
opts = [str(o).strip() for o in (row.get("options") or []) if str(o).strip()]
gold = str(row["answer"]).strip()
is_mc = bool(opts)
letters = [chr(65 + i) for i in range(len(opts))]
bare = is_mc and all(re.fullmatch(r"\(?[A-Za-z]\)?\.?", o) for o in opts)
if is_mc:
qtype, atype, prec = "multi_choice", "text", 2
choices = [""] * len(opts) if bare else opts # bare letters: option values are in the image
else:
qtype, choices, g = "free_form", [], gold.replace(",", "")
if re.fullmatch(r"-?\d+", g):
atype, prec = "integer", 0
elif re.fullmatch(r"-?\d*\.\d+", g):
atype, prec = "float", len(g.split(".")[1])
else:
atype, prec = "text", 2
return {"question_type": qtype, "answer_type": atype, "choices": choices,
"answer": gold, "answer_raw": gold,
"answer_is_letter": is_mc and gold.upper() in letters,
"precision": prec, "unit": "",
"task": str(row.get("subject", "")), "category": str(row.get("subject", "")),
"context": "", "grade": str(row.get("level", "")), "skills": [str(row.get("subject", ""))]}
def final_prompt(ex):
if ex["question_type"] == "multi_choice":
tail = "\n\nThink step by step, then give the final answer as the option letter only, in the form \\boxed{A}."
else:
tail = "\n\nThink step by step, then give the final answer only, in the form \\boxed{...}."
return ex["prompt"] + tail
|