File size: 2,126 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 | import argparse,json
from pathlib import Path
from metrics import summarize,bootstrap
from environment import Shop
R=Path(__file__).resolve().parent
p=argparse.ArgumentParser();p.add_argument('outputs',type=Path);a=p.parse_args()
rows=[r for r in json.loads((R.parent/'data/tasks.json').read_text()) if r['split']=='holdout']
results={c:json.loads((a.outputs/(c+'.json')).read_text())['results'] for c in ['base_agent','distilled_agent','gate_controller']}
summaries={c:summarize(rows,r) for c,r in results.items()};interval=bootstrap(rows,results['base_agent'],results['distilled_agent']);b=summaries['base_agent'];d=summaries['distilled_agent']
criteria={'gain_15pp_and_positive_ci':(d['success']-b['success'])/72>=.15 and interval[0]>0,'wrong_filter_not_worse':d['wrong_filter_count']<=b['wrong_filter_count'],'explicit_recall_60pct':d['explicit_retained']/d['explicit_total']>=.6,'parse_failures_at_most_20pct':d['parse_failures']/72<=.2}
controls={}
for name in ['constant_no','four_phrase']:
predictions=[];matches=0
for row in rows:
text=row['input']['text'].lower();gate=next((g for phrase,g in [('must have','YES'),('do not require','NO'),('not decided','UNSURE'),('compatible with','FIT')] if phrase in text),None) if name=='four_phrase' else 'NO'
matches+=gate is not None
if gate is None:predictions.append({'id':row['id'],'success':False,'error':'NO_MATCH','calls':[],'steps':0});continue
proxy={**row,'status':{'YES':'explicit','NO':'not_stated','FIT':'compatibility_only','UNSURE':'ambiguous'}[gate]}
env=Shop(proxy);env.teacher();env.row=row
predictions.append({'id':row['id'],'success':env.success(),'error':None,'calls':env.calls,'steps':len(env.calls)})
controls[name]={'matched':matches,'metrics':summarize(rows,predictions)}
report={'controls':controls,'summaries':summaries,'paired_family_bootstrap_95':interval,'adoption_criteria':criteria,'adopt':all(criteria.values()),'limitations':'Rule-teacher SFT; synthetic exposed holdout; simulated catalog; model-assisted labels.'}
(a.outputs/'local-results.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report,indent=2))
|