Download code/score_frozen.py from ImmunoGraph-Bench/ImmunoGraphBench2027: direct link, hf CLI and curl.
- Browser
- Download file 3.18 kB
-
https://huggingface.co/datasets/ImmunoGraph-Bench/ImmunoGraphBench2027/resolve/main/code/score_frozen.py
- Command line
-
hf download hf://datasets/ImmunoGraph-Bench/ImmunoGraphBench2027/code/score_frozen.py
-
curl -L -o score_frozen.py https://huggingface.co/datasets/ImmunoGraph-Bench/ImmunoGraphBench2027/resolve/main/code/score_frozen.py
3.18 kB
| """Read-only aggregation of explicitly selected existing alias decisions. | |
| Never calls an LLM, changes an answer, infers aliases, or silently chooses a judge. | |
| """ | |
| import argparse,collections,json | |
| from pathlib import Path | |
| def summarize(rows, field, error_policy): | |
| groups=collections.defaultdict(lambda:dict(rows=0,scored=0,correct=0,errors=0,unscored=0)) | |
| seen=set() | |
| for r in rows: | |
| qid=r.get('qa_id');condition=r.get('condition',r.get('setting')) | |
| if not qid or not condition:raise ValueError('Every answer must have qa_id and condition/setting') | |
| key=(qid,condition) | |
| if key in seen:raise ValueError(f'Duplicate answer key: {key}; resolve explicitly before scoring') | |
| seen.add(key) | |
| error=bool(r.get('error') or r.get('api_error')) | |
| value=r.get(field) | |
| for group in [(condition,'Overall'),(condition,str(r.get('subtype') or 'unknown'))]: | |
| g=groups[group];g['rows']+=1;g['errors']+=int(error) | |
| if error and error_policy=='exclude':continue | |
| if error and error_policy=='count_as_incorrect':value=False | |
| if not isinstance(value,bool):g['unscored']+=1;continue | |
| g['scored']+=1;g['correct']+=int(value) | |
| result=[] | |
| for (c,s),g in sorted(groups.items()): | |
| result.append(dict(condition=c,subtype=s,**g,accuracy_pct=100*g['correct']/g['scored'] if g['scored'] else None)) | |
| return dict(correct_field=field,error_policy=error_policy,unique_answer_keys=len(seen),groups=result) | |
| def main(): | |
| p=argparse.ArgumentParser(description=__doc__) | |
| p.add_argument('--answers',required=True,type=Path) | |
| p.add_argument('--correct-field',required=True) | |
| p.add_argument('--error-policy',required=True,choices=['exclude','count_as_incorrect','stored']) | |
| p.add_argument('--qa',type=Path,help='Optional exact evaluation QA subset; joins source_medium_qa_id or qa_id') | |
| p.add_argument('--out',required=True,type=Path) | |
| a=p.parse_args(); qa={} | |
| if a.qa: | |
| with a.qa.open(encoding='utf-8-sig') as f: | |
| for line in f: | |
| if not line.strip():continue | |
| r=json.loads(line);qid=r.get('source_medium_qa_id') or r['qa_id'] | |
| if qid in qa:raise ValueError(f'Duplicate QA subset ID: {qid}') | |
| qa[qid]=r | |
| if not qa:raise ValueError('Explicit QA subset is empty; refusing full-set fallback') | |
| def records(): | |
| with a.answers.open(encoding='utf-8-sig') as f: | |
| for line in f: | |
| if not line.strip():continue | |
| r=json.loads(line) | |
| if qa: | |
| qid=r.get('source_medium_qa_id') or r['qa_id'] | |
| if qid not in qa:continue | |
| r=dict(r,subtype=qa[qid].get('subtype',r.get('subtype'))) | |
| yield r | |
| result=summarize(records(),a.correct_field,a.error_policy) | |
| result['qa_subset_size']=len(qa) if a.qa else None | |
| a.out.parent.mkdir(parents=True,exist_ok=True) | |
| a.out.write_text(json.dumps(result,ensure_ascii=False,indent=2),encoding='utf-8') | |
| print(json.dumps({'output':str(a.out),'keys':result['unique_answer_keys']})) | |
| if __name__=='__main__':main() | |