Download method-v2/analyze.py from Noddybear/encoding-tax-e6-exploratory-pilot: direct link, hf CLI and curl.
- Browser
- Download file 3.26 kB
-
https://huggingface.co/datasets/Noddybear/encoding-tax-e6-exploratory-pilot/resolve/main/method-v2/analyze.py
- Command line
-
hf download hf://datasets/Noddybear/encoding-tax-e6-exploratory-pilot/method-v2/analyze.py
-
curl -L -o analyze.py https://huggingface.co/datasets/Noddybear/encoding-tax-e6-exploratory-pilot/resolve/main/method-v2/analyze.py
3.26 kB
| """Descriptive pilot summaries exclusively from authoritative extension .eval logs.""" | |
| from pathlib import Path | |
| import json | |
| import pandas as pd | |
| from inspect_ai.log import read_eval_log | |
| from encoding_tax.common import ROOT,digest,write_json,now | |
| from encoding_tax.scoring import auroc | |
| def main(): | |
| root=ROOT/'results/e6-exploratory-v2/pilot/inspect';out=ROOT/'reports/e6-exploratory-v2/pilot';out.mkdir(parents=True,exist_ok=True) | |
| observations={};hashes={} | |
| for path in sorted(root.glob('*.eval')): | |
| log=read_eval_log(path);hashes[str(path.relative_to(ROOT))]=digest(path) | |
| if not log.eval.metadata.get('exploratory') or log.eval.task!='E6X2_pilot':raise ValueError('Mixed study logs') | |
| for sample in log.samples or []: | |
| m=sample.metadata;key=(m['reader'],sample.id) | |
| row={k:m[k] for k in ['reader','mode','policy','representation','rounds','budget','label','cluster_id','leaves']} | |
| row.update(sample_id=sample.id,error=bool(sample.error),raw=sample.output.completion if sample.output else '',scratchpad=m.get('scratchpad'),reasoning_end=m.get('reasoning_end'),**m.get('outcome',{})) | |
| requests=m.get('requests',[]) | |
| row['prompt_hashes']=[r.get('prompt_sha256') for r in requests] | |
| for field in ['completion_tokens','prompt_tokens','cost']: | |
| values=[r.get(field) for r in requests];row[field]=sum(values) if len(values)==2 and all(x is not None for x in values) else None | |
| if key in observations and not observations[key]['error']: | |
| old=observations[key] | |
| if not row['error'] and (old['raw']!=row['raw'] or old['prompt_hashes']!=row['prompt_hashes']):raise ValueError('Conflicting completed duplicate') | |
| continue | |
| observations[key]=row | |
| frame=pd.DataFrame(observations.values());frame.to_json(out/'observations.jsonl',orient='records',lines=True) | |
| rows=[] | |
| keys=['reader','mode','policy','representation','rounds','budget'] | |
| for k,g in frame.groupby(keys,dropna=False): | |
| good=g[~g.error];row=dict(zip(keys,k));row.update(n=len(g),operational_errors=int(g.error.sum()),completed=len(good),problems=g.cluster_id.nunique(),completion_tokens=good.completion_tokens.mean(),input_tokens=good.prompt_tokens.mean(),cost=good.cost.sum(min_count=1),validity=good.valid.mean(),scratchpad_cap_rate=good.reasoning_end.eq('length').mean()) | |
| if row['mode']=='monitor': | |
| row.update(auroc=auroc(good.label,good.probability),recall=good[good.label==1].alert.mean(),fpr=good[good.label==0].alert.mean(),log_loss=good.log_loss.mean()) | |
| valid=good[good.valid==True];row['valid_only_auroc']=auroc(valid.label,valid.probability) | |
| else: | |
| for metric in ['decoded_exact','equation_correct','first_error_correct','all_correct']:row[metric]=good[metric].mean() | |
| rows.append(row) | |
| pd.DataFrame(rows).to_csv(out/'conditions.csv',index=False) | |
| write_json(out/'provenance.json',{'created_at':now(),'exploratory':True,'descriptive_pilot_only':True,'expected_samples':9120,'observed_samples':len(frame),'operational_errors':int(frame.error.sum()),'source_log_hashes':hashes}) | |
| print('Pilot analysis:',out) | |
| if __name__=='__main__':main() | |