Datasets:
Download scripts/run_ladder.py from addyo07/vox-tier2-backup: direct link, hf CLI and curl.
- Browser
- Download file 4.79 kB
-
https://huggingface.co/datasets/addyo07/vox-tier2-backup/resolve/main/scripts/run_ladder.py
- Command line
-
hf download hf://datasets/addyo07/vox-tier2-backup/scripts/run_ladder.py
-
curl -L -o run_ladder.py https://huggingface.co/datasets/addyo07/vox-tier2-backup/resolve/main/scripts/run_ladder.py
4.79 kB
| #!/usr/bin/env python3 | |
| """Run the data-scaling ladder: identical hparams, only disfluency count varies. | |
| Every rung is evaluated on BOTH frozen validation splits: | |
| V_real = pilot_v2_val_adjudicated.jsonl (real human Switchboard -- the gate) | |
| V_syn = ladder/V_syn.jsonl (held-out synthetic -- domain-gap probe) | |
| """ | |
| import json, os, subprocess, sys, time | |
| PY = "/opt/vox/venv/bin/python" | |
| LAD = "/opt/vox/sandbox/ladder" | |
| BENCH = "/opt/vox/sandbox/benchmarks" | |
| V_REAL = "/opt/vox/sandbox/corpus/pilot_v2_val_adjudicated.jsonl" | |
| V_SYN = f"{LAD}/V_syn.jsonl" | |
| RUNGS = [("L0_baseline_3k", None), | |
| ("L1_5k", f"{LAD}/L1_5k_train.jsonl"), | |
| ("L2_10k", f"{LAD}/L2_10k_train.jsonl"), | |
| ("L3_full", f"{LAD}/L3_full_train.jsonl")] | |
| MODELS = ["roberta-base", "deberta-v3-base"] | |
| COMMON = "--seed 42 --epochs 8 --batch-size 16 --lr-encoder 3e-5 --lr-head 1e-3 --max-len 128 --dtype float32" | |
| def sh(cmd, log): | |
| with open(log, "a") as f: | |
| f.write(f"\n$ {' '.join(cmd)}\n"); f.flush() | |
| return subprocess.run(cmd, stdout=f, stderr=subprocess.STDOUT).returncode | |
| def main(): | |
| os.makedirs(BENCH, exist_ok=True) | |
| summary = [] | |
| for rname, train in RUNGS: | |
| for m in MODELS: | |
| ck = f"/opt/vox/temp/ckpt/{rname}__{m}" | |
| log = f"/opt/vox/temp/logs/ladder_{rname}_{m}.log" | |
| t0 = time.time() | |
| if train is None: # L0 = the pre-Phase-C checkpoint, already trained | |
| src = f"/opt/vox/temp/ckpt/{m}" | |
| if not os.path.isdir(src): | |
| print(f"skip L0 {m}: no baseline ckpt"); continue | |
| ck = src | |
| elif not os.path.exists(f"{ck}/train_meta.json"): | |
| rc = sh([PY, "-u", "/opt/vox/sandbox/scripts/train_span.py", "--model", | |
| f"FacebookAI/roberta-base" if m == "roberta-base" else "microsoft/deberta-v3-base", | |
| "--out", ck, "--train", train] + COMMON.split(), log) | |
| if rc != 0: | |
| print(f"TRAIN FAIL {rname} {m} rc={rc}"); continue | |
| meta = json.load(open(f"{ck}/train_meta.json")) | |
| print(f"{rname:16} {m:18} n={meta['n_train']:6} loss {meta['train_log'][0]['train_loss']}" | |
| f"->{meta['train_log'][-1]['train_loss']} ({meta['wall_s']}s)", flush=True) | |
| row = {"rung": rname, "model": m, "n_train": meta["n_train"], | |
| "final_train_loss": meta["train_log"][-1]["train_loss"], | |
| "train_s": meta["wall_s"]} | |
| for vname, vpath in (("real", V_REAL), ("syn", V_SYN)): | |
| ej = f"{BENCH}/ladder_{rname}_{m}_{vname}.json" | |
| if not os.path.exists(ej): | |
| rc = sh([PY, "-u", "/opt/vox/sandbox/scripts/eval_span.py", "--model", ck, | |
| "--tag", f"{rname}_{m}_{vname}", "--out", ej, "--val", vpath], log) | |
| if rc != 0 or not os.path.exists(ej): | |
| print(f" EVAL FAIL {rname} {m} {vname}"); continue | |
| b = json.load(open(ej))["best"] | |
| row[f"{vname}_EM"] = b["exact_match"] | |
| row[f"{vname}_F1"] = b["span_word"]["f1"] | |
| row[f"{vname}_P"] = b["span_word"]["precision"] | |
| row[f"{vname}_R"] = b["span_word"]["recall"] | |
| row[f"{vname}_overdel"] = b["over_deletion_rate"] | |
| row[f"{vname}_harmful"] = b["harmful_span_rate"] | |
| row[f"{vname}_thr"] = b["threshold"] | |
| row[f"{vname}_gate"] = b["passes_gate"] | |
| row[f"{vname}_DIS_EM"] = b["per_category"].get("DISFLUENCY", {}).get("exact_match") | |
| summary.append(row) | |
| print(f" REAL EM={row.get('real_EM')} F1={row.get('real_F1')} " | |
| f"overdel={row.get('real_overdel')}% harmful={row.get('real_harmful')}% " | |
| f"DIS_EM={row.get('real_DIS_EM')} gate={row.get('real_gate')}", flush=True) | |
| print(f" SYN EM={row.get('syn_EM')} F1={row.get('syn_F1')} " | |
| f"overdel={row.get('syn_overdel')}% harmful={row.get('syn_harmful')}% " | |
| f"DIS_EM={row.get('syn_DIS_EM')}", flush=True) | |
| json.dump(summary, open(f"{BENCH}/ladder_summary.json", "w"), indent=2) | |
| print("\n=== LADDER (V_real, production-representative) ===") | |
| print(f"{'rung':16} {'model':18} {'n':>6} {'EM':>7} {'F1':>6} {'DIS_EM':>7} " | |
| f"{'overdel':>8} {'harmful':>8} gate") | |
| for s in summary: | |
| print(f"{s['rung']:16} {s['model']:18} {s['n_train']:>6} {str(s.get('real_EM')):>7} " | |
| f"{str(s.get('real_F1'))[:6]:>6} {str(s.get('real_DIS_EM')):>7} " | |
| f"{str(s.get('real_overdel')):>8} {str(s.get('real_harmful')):>8} {s.get('real_gate')}") | |
| if __name__ == "__main__": | |
| main() | |