Datasets:
Download scripts/evaluate.py from RL-MIND/SUM: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/datasets/RL-MIND/SUM/resolve/main/scripts/evaluate.py
- Command line
-
hf download hf://datasets/RL-MIND/SUM/scripts/evaluate.py
-
curl -L -o evaluate.py https://huggingface.co/datasets/RL-MIND/SUM/resolve/main/scripts/evaluate.py
1.47 kB
| """Score explicit option-letter predictions against the frozen SUM release. | |
| Usage: python scripts/evaluate.py --annotations dataset.json --predictions predictions.jsonl | |
| Each prediction is {"id":"000001", "prediction":"A"}; absent/invalid answers count as incorrect. | |
| """ | |
| import argparse | |
| import collections | |
| import json | |
| from pathlib import Path | |
| p=argparse.ArgumentParser() | |
| p.add_argument('--annotations',type=Path,required=True) | |
| p.add_argument('--predictions',type=Path,required=True) | |
| a=p.parse_args() | |
| rows=json.loads(a.annotations.read_text()) | |
| predictions={} | |
| for line in a.predictions.read_text().splitlines(): | |
| if not line.strip():continue | |
| r=json.loads(line) | |
| if r['id'] in predictions:raise ValueError('Duplicate prediction ID: '+r['id']) | |
| predictions[r['id']]=str(r['prediction']).strip().upper() | |
| known={r['id'] for r in rows} | |
| if set(predictions)-known:raise ValueError('Unknown prediction IDs') | |
| groups=collections.defaultdict(lambda:dict(correct=0,total=0,missing=0,invalid=0)) | |
| for r in rows: | |
| answer=predictions.get(r['id']) | |
| valid={c['label'] for c in r['choices']} | |
| for key in ['overall','source/'+r['source_dataset'],'task/'+r['task_type']]: | |
| s=groups[key];s['total']+=1 | |
| s['correct']+=int(answer==r['answer']) | |
| s['missing']+=int(answer is None) | |
| s['invalid']+=int(answer is not None and answer not in valid) | |
| for s in groups.values():s['accuracy']=s['correct']/s['total'] | |
| print(json.dumps(groups,indent=2)) | |