"""Adapt the lv-mccarthy arms for voice_distance.py, and refuse if its reference is empty. Same contract as the lv-hemingway sibling — the arm NAMES are the only real difference, and the control must carry the substring `unadapted` or voice_distance.py cannot identify it and prints an empty vs-control table instead of an error. voice_distance.py expects: - files matching voice..jsonl in the eval dir - a `continuation` field per record (gen_beats_chat writes `raw`) - a `seed` field (present) - the control arm's NAME to contain the substring "unadapted" - a reference built from corpus records whose split == "val" """ import json, sys from collections import Counter from pathlib import Path CORP = Path("/home/infra-ops/lv-mccarthy/corpus-renamed/copies") EVAL = Path("/home/infra-ops/r49-runs/mccarthy-eval") c = Counter() n = 0 for p in sorted(CORP.glob("*.jsonl")): for line in p.read_text(encoding="utf-8").splitlines(): if not line.strip(): continue r = json.loads(line) n += 1 c[r.get("split")] += 1 print(f"corpus records: {n} split values: {dict(c)}") if c.get("val", 0) == 0: print("== REFUSING: no split=val records; voice_distance would build an EMPTY reference") print(" and every delta_cb would be meaningless rather than absent.") sys.exit(1) # Arms are DISCOVERED, not listed. AMENDMENT 3 added two and a hardcoded dict would have # silently dropped them from the voice table while every other axis scored them -- the arm # would be missing rather than failing, which is the worse of the two. found = sorted(EVAL.glob("beats5.*.jsonl")) if not found: print(f"== REFUSING: no beats5.*.jsonl in {EVAL}") sys.exit(1) NAMES = {} for f in found: arm = f.stem.replace("beats5.", "") NAMES[arm] = "base-unadapted" if arm == "base" else arm if "base-unadapted" not in NAMES.values(): print("== REFUSING: no `base` arm, so voice_distance would have no control to compare against") sys.exit(1) print(f"arms discovered: {', '.join(sorted(NAMES))}") for src_arm, out_arm in NAMES.items(): src = EVAL / f"beats5.{src_arm}.jsonl" if not src.exists(): print(f"== missing {src}") sys.exit(1) rows = [json.loads(l) for l in src.read_text(encoding="utf-8").splitlines() if l.strip()] out = EVAL / f"voice.{out_arm}.jsonl" with out.open("w", encoding="utf-8") as fh: for r in rows: fh.write(json.dumps({"id": r["id"], "seed": r["seed"], "continuation": r["raw"]}, ensure_ascii=False) + "\n") print(f" {src.name} -> {out.name} ({len(rows)} records)") print("ready")