File size: 1,178 Bytes
b6ae5c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Fast validation-only report from hash-checked fixed encoder features."""
import argparse,json
from pathlib import Path
import numpy as np
from decision_model.pipeline import datasets,load_checkpoint,logits_for
from decision_model.learning import softmax,metrics

p=argparse.ArgumentParser();p.add_argument('--model',type=Path,required=True)
p.add_argument('--features',type=Path,required=True);args=p.parse_args()
sets=datasets(args.features,splits=('validation',))
w,_,_,_=load_checkpoint(args.model,sets);a,m=sets['validation'];logits=logits_for(a,w,m['rows'])
result={}
for lang in ['uk','en']:
 for kind in ['noul','choice','score']:
  sel=np.array([r['language']==lang and r['type']==kind and r['demo'] for r in m['rows']])
  v=metrics(softmax(logits[sel]),a['gold'][sel],ordinal=kind=='score',positive_label=1 if kind=='noul' else None)
  result[lang+'/'+kind]={k:v[k] for k in ['n','accuracy','macro_f1','nll']+(['mae'] if kind=='score' else [])+
                       (['positive_recall','positive_precision'] if kind=='noul' else [])}
(args.model/'validation-cached.json').write_text(json.dumps(result,indent=2),encoding='utf-8')
print(json.dumps(result,indent=2))