Datasets:
Download code/rescore_mathvision.py from Miiche/vpp-mathvision-seed-variance: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/datasets/Miiche/vpp-mathvision-seed-variance/resolve/main/code/rescore_mathvision.py
- Command line
-
hf download hf://datasets/Miiche/vpp-mathvision-seed-variance/code/rescore_mathvision.py
-
curl -L -o rescore_mathvision.py https://huggingface.co/datasets/Miiche/vpp-mathvision-seed-variance/resolve/main/code/rescore_mathvision.py
1.14 kB
| #!/usr/bin/env python3 | |
| """Rescore stored MathVision outputs with the current scorer (writes outputs_rescored.jsonl | |
| next to each outputs.jsonl). v2: multiple-choice replies given as option *content* are | |
| mapped to the option letter, because the prompt listed choices without letter labels.""" | |
| import json | |
| import sys | |
| from pathlib import Path | |
| from video_position_probing import mathvision as mv | |
| for path in sys.argv[1:]: | |
| src = Path(path) | |
| changed = n = 0 | |
| with src.open() as fin, src.with_name("outputs_rescored.jsonl").open("w") as fout: | |
| for line in fin: | |
| r = json.loads(line) | |
| if r.get("status") == "ok": | |
| new = mv.is_correct(r["prediction"], r["gold"], r["options"]) | |
| r["correct_v1"], r["correct"], r["scorer"] = r["correct"], new, "mathvision-v2" | |
| if r["options"]: | |
| r["predicted_letter"] = mv.option_letter(r["prediction"], r["options"]) | |
| changed += new != r["correct_v1"]; n += 1 | |
| fout.write(json.dumps(r, ensure_ascii=False) + "\n") | |
| print(json.dumps({"file": str(src), "rows": n, "changed": changed})) | |