Datasets:
Download scoring/score.py from ScaleAI/MA-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/datasets/ScaleAI/MA-Bench/resolve/main/scoring/score.py
- Command line
-
hf download hf://datasets/ScaleAI/MA-Bench/scoring/score.py
-
curl -L -o score.py https://huggingface.co/datasets/ScaleAI/MA-Bench/resolve/main/scoring/score.py
2.09 kB
| """MA-Bench scorer. Standalone: python score.py rubric_items.jsonl verdicts.jsonl | |
| verdicts.jsonl: one line per graded brief, {"case_id": "C1", "brief_id": "...", "failed_items": ["S1-01-n", ...]} | |
| where failed_items are the rubric item_ids the judge marked as NOT satisfying pass_condition (the judge returns | |
| failures only; every unlisted item counts as passed). For D and CD items the pass condition asserts the mistake is | |
| present, so an unlisted (passed) negative item incurs its negative weight. | |
| Prints per-brief unweighted pass rate and severity-weighted score, then per-case means. | |
| """ | |
| import json | |
| import sys | |
| import collections | |
| import statistics as st | |
| def load_items(path): | |
| by = collections.defaultdict(dict) | |
| for line in open(path): | |
| it = json.loads(line) | |
| by[it["case_id"]][it["item_id"]] = it | |
| return by | |
| def score(items, failed): | |
| pos = [i for i in items.values() if i["weight"] > 0] | |
| neg = [i for i in items.values() if i["weight"] < 0] | |
| earned = sum(i["weight"] for i in pos if i["item_id"] not in failed) | |
| incurred = sum( | |
| i["weight"] for i in neg if i["item_id"] not in failed | |
| ) # mistake present | |
| correct = sum(1 for i in pos if i["item_id"] not in failed) + sum( | |
| 1 for i in neg if i["item_id"] in failed | |
| ) | |
| return { | |
| "pass_rate": correct / len(items), | |
| "weighted": (earned + incurred) / sum(i["weight"] for i in pos), | |
| "detrimental_present": sum(1 for i in neg if i["item_id"] not in failed), | |
| } | |
| def main(): | |
| items = load_items(sys.argv[1]) | |
| per_case = collections.defaultdict(list) | |
| for line in open(sys.argv[2]): | |
| v = json.loads(line) | |
| s = score(items[v["case_id"]], set(v["failed_items"])) | |
| per_case[v["case_id"]].append(s) | |
| print( | |
| f"{v['case_id']}\t{v.get('brief_id', '')}\tpass={s['pass_rate']:.3f}\tweighted={s['weighted']:.3f}\tdetrimental={s['detrimental_present']}" | |
| ) | |
| for c, ss in sorted(per_case.items()): | |
| print( | |
| f"# {c}\tn={len(ss)}\tpass={st.mean(x['pass_rate'] for x in ss):.3f}\tweighted={st.mean(x['weighted'] for x in ss):.3f}" | |
| ) | |
| if __name__ == "__main__": | |
| main() | |