Download tests/test_edition.py from Manprot/MPBench0-1126: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/datasets/Manprot/MPBench0-1126/resolve/main/tests/test_edition.py
- Command line
-
hf download hf://datasets/Manprot/MPBench0-1126/tests/test_edition.py
-
curl -L -o test_edition.py https://huggingface.co/datasets/Manprot/MPBench0-1126/resolve/main/tests/test_edition.py
2.13 kB
| """Every frozen task: its own answer passes, wrong options and echoes don't.""" | |
| import json | |
| import sys | |
| from pathlib import Path | |
| B = Path(__file__).resolve().parent.parent | |
| sys.path.insert(0, str(B)) | |
| from mpbench import score as S | |
| bad, n = [], 0 | |
| for name in json.loads((B / "data/edition.json").read_text())["sections"]: | |
| tasks = [json.loads(x) for x in (B / f"data/{name}.jsonl").read_text().split("\n") if x] | |
| known = S.known_words(tasks) | |
| for t in tasks: | |
| n += 1 | |
| kind, ok, wrong = t["type"], [], ["", "I don't know."] if t["type"] not in ("ideas", "html") else [""] | |
| if kind == "text": | |
| ok = t["answers"] | |
| wrong += t.get("reject", []) | |
| elif kind == "ideas": | |
| ok = [" ".join(i[0] for i in t["ideas"])] | |
| elif kind == "number": | |
| ok = [str(t["answer"]), f"The answer is {t['answer']}."] | |
| elif kind == "tool": | |
| args = {k: v["any"][0] if isinstance(v, dict) and "any" in v else v for k, v in t["call"]["arguments"].items()} | |
| ok = [json.dumps({"name": t["call"]["name"], "arguments": args})] | |
| for k, v in args.items(): | |
| if isinstance(v, bool): | |
| other = not v | |
| elif isinstance(v, str) and k == "expression": | |
| other = v.replace("*", "+") if "*" in v else v.replace("+", "*") if "+" in v else v.replace("-", "+") if "-" in v else v.replace("/", "*") | |
| else: | |
| other = "zzz" | |
| wrong.append(json.dumps({"name": t["call"]["name"], "arguments": {**args, k: other}})) | |
| wrong += [w for w in t.get("not_typos", []) if kind == "text" and not any(S.same_word(x, w) for a in t["answers"] for x in S.words_of(a) if x == w)] | |
| if t.get("exact"): | |
| wrong.append(t["question"].split(":")[-1].strip()) | |
| bad += [(t["id"], "answer fails", a) for a in ok if S.score(a, t, known) != 1] | |
| bad += [(t["id"], "wrong passes", a) for a in wrong if S.score(a, t, known) != 0] | |
| for b in bad: | |
| print("FAIL", b) | |
| print(f"{n} tasks checked, {len(bad)} problems") | |
| sys.exit(bool(bad)) | |