Download appendix/code/score_regression.py from BradJu/attribute-ownership-negative-experiments: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/datasets/BradJu/attribute-ownership-negative-experiments/resolve/main/appendix/code/score_regression.py
- Command line
-
hf download hf://datasets/BradJu/attribute-ownership-negative-experiments/appendix/code/score_regression.py
-
curl -L -o score_regression.py https://huggingface.co/datasets/BradJu/attribute-ownership-negative-experiments/resolve/main/appendix/code/score_regression.py
2.16 kB
| """Score only complete new outputs; no old result mutation.""" | |
| import json,sys | |
| from pathlib import Path | |
| from metrics import summarize,bootstrap | |
| from environment import Shop | |
| R=Path(__file__).resolve().parent | |
| def score(directory): | |
| rows=[r for r in json.loads((R.parent/'data/tasks.json').read_text()) if r['split']=='holdout'] | |
| plan=json.loads((R.parent/'config/regression.json').read_text());out={};all_results={} | |
| for name in plan['conditions']: | |
| payload=json.loads((directory/f'{name}.holdout_regression.json').read_text()) | |
| assert payload['complete'] and payload['expected']==len(rows) | |
| predictions=payload['results'];lookup={p['id']:p for p in predictions} | |
| assert len(lookup)==len(predictions)==len(rows) and set(lookup)=={r['id'] for r in rows} | |
| for row in rows: | |
| p=lookup[row['id']];shop=Shop(row) | |
| for call in p['calls']:assert shop.step(call['action'])==call['result'] | |
| assert p['success']==(not p['error'] and shop.success()) | |
| m=summarize(rows,predictions);m['ambiguous_first_call_attempts']=0;m['unjustified_filter_tasks']=0 | |
| for row in rows: | |
| p=lookup[row['id']] | |
| try:first=json.loads(p['raw_outputs'][0]).get('tool') | |
| except (ValueError,IndexError,AttributeError):first=None | |
| m['ambiguous_first_call_attempts']+=row['status']=='ambiguous' and first=='ask_clarification' | |
| justified=row['status']=='explicit';bad=False | |
| for c in p['calls']: | |
| if c['action']['tool']=='ask_clarification' and row['status']=='ambiguous':justified=c['result']['answer']['required'] | |
| if c['action']['tool']=='search_catalog' and c['action']['arguments']['filters'] and not justified:bad=True | |
| m['unjustified_filter_tasks']+=bad | |
| out[name]=m;all_results[name]=predictions | |
| out['paired_success_intervals']={n:bootstrap(rows,all_results['base_agent'],all_results[n]) for n in plan['conditions'] if n!='base_agent'} | |
| out['note']='Seen-set regression, not fresh generalization. Legacy wrong-filter metric retained; unjustified filters is separately declared before this run.' | |
| (directory/'local-summary.json').write_text(json.dumps(out,indent=2)+'\n');return out | |
| if __name__=='__main__':print(json.dumps(score(Path(sys.argv[1])),indent=2)) | |