File size: 2,159 Bytes
c72da75 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | """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))
|