"""Reproduce the FinePhrase G-Vendi pipeline and swap its proxy to the base model, on the 83-cell Fig 22 grid. Three pipelines on a common downstream grid (FinePhrase Fig 22, 83 cells after the 7 footnote-1 exclusions): pub the playbook's published pipeline (Qwen3-0.6B instruct, last MLP down_proj, 1024-index seed-42 sketch, 256-token truncation, 1000 docs/cell) repro Same settings as pub, re-run end-to-end prx06bb Swap proxy: Qwen3-0.6B (instruct) -> Qwen3-0.6B-Base For each pipeline we correlate G-Vendi against each downstream score two ways: raw : Spearman pooled across all 83 cells zS : Spearman after z-scoring within each (bucket, prompt) group (n=74; groups with fewer than 3 cells are dropped). p-values are scipy two-tailed vs 0. Inputs (relative to the artifact root): data/pub.json the playbook's published per-cell G-Vendi data/repro/*.json reproduction data/prx06bb/*.json base-proxy swap data/downstream_scores.json per-run downstream scores (Figure 22 source) Run from the artifact root: python gvendi_correlations.py """ import glob, json, math from collections import defaultdict from scipy.stats import pearsonr, spearmanr EXCLUDED_FOOTNOTE1 = { "format/article:1b-hq", "format/commentary:1b-hq", "format/discussion:1b-hq", "format/tutorial:1b-hq", "format/tutorial:12b-hq", "format/faq:1b-lq", "format/faq:12b-lq", } # (downstream-score key, short label), 8 aggregates + 12 individual benchmarks. SCORE_COLS = [ ("agg_score_macro", "macro"), ("agg_score_micro", "micro"), ("agg_score_RC", "RC"), ("agg_score_GK", "GK"), ("agg_score_NLU", "NLU"), ("agg_score_MATH", "MATH"), ("agg_score_TABLE", "TABLE"), ("agg_score_RES", "RES"), ("lighteval|arc_cf:easy|3/prob_norm_token", "arc"), ("lighteval|drop|3/prob_norm_token", "drop"), ("lighteval|gsm8k|3/prob_norm_token", "gsm8k"), ("lighteval|hellaswag_cf|3/prob_norm_token", "hella"), ("lighteval|openbookqa_cf|3/prob_norm_token", "obqa"), ("lighteval|piqa_cf|3/prob_norm_token", "piqa"), ("lighteval|squad_v2|3/prob_norm_token", "squad"), ("lighteval|treb_qa|3/prob_norm_token", "treb"), ("lighteval|wikitablequestions|3/prob_norm_token", "wikitab"), ("lighteval|winogrande_cf|3/prob_norm_token", "wino"), ("lighteval|xcsqa_cf|3/prob_norm_token", "xcsqa"), ("lighteval|mmlu_redux_cf:_average|3/prob_norm_token", "mmlu"), ] # Downstream scores come from the playbook's Figure 22 source (rephrasing_metadata.json), # keyed by run = "bucket/prompt-suffix", so the correlations reproduce the figure exactly. downstream = json.load(open("data/downstream_scores.json")) pub_gv = json.load(open("data/pub.json")) def load_by_cell(globpat): out = {} for fp in glob.glob(globpat): d = json.load(open(fp)) out[d["cell"]] = float(d["g_vendi"]) return out repro_gv = load_by_cell("data/repro/*.json") prx06bb_gv = load_by_cell("data/prx06bb/*.json") print(f"loaded: pub {len(pub_gv)}, repro {len(repro_gv)}, prx06bb {len(prx06bb_gv)}\n") # row = (bucket, prompt, pub_gv, repro_gv, prx06bb_gv, scores) PUB, REPRO, PRX, SCORES = 2, 3, 4, 5 PIPES = [("pub", PUB), ("repro", REPRO), ("prx06bb", PRX)] rows = [] missing = [] for cell in sorted(repro_gv): if cell in EXCLUDED_FOOTNOTE1: continue bucket_prompt, suffix = cell.rsplit(":", 1) bucket, prompt = bucket_prompt.split("/", 1) run = f"{bucket}/{prompt}-{suffix}" # published / downstream files use a hyphen if run not in pub_gv or run not in downstream: missing.append(run); continue rows.append((bucket, prompt, float(pub_gv[run]["g_vendi_score"]), repro_gv[cell], prx06bb_gv[cell], downstream[run])) print(f"matched cells: {len(rows)} (target 83)") if missing: print(f"missing g-vendi or downstream for: {missing}") print() def raw_spearman(idx, col): return spearmanr([r[idx] for r in rows], [r[SCORES][col] for r in rows]) def zwithin_spearman(idx, col): """Spearman after z-scoring G-Vendi and the metric within each (bucket, prompt) group; groups with fewer than 3 cells are dropped. Returns (result, n_used).""" byp = defaultdict(list) for r in rows: byp[(r[0], r[1])].append((r[idx], r[SCORES][col])) zg, zm = [], [] for v in byp.values(): n = len(v) if n < 3: continue gs = [x[0] for x in v]; ms = [x[1] for x in v] mg, mm = sum(gs) / n, sum(ms) / n sg = math.sqrt(sum((x - mg) ** 2 for x in gs) / n) sm = math.sqrt(sum((x - mm) ** 2 for x in ms) / n) for g, mc in v: zg.append((g - mg) / sg if sg else 0.0) zm.append((mc - mm) / sm if sm else 0.0) return spearmanr(zg, zm), len(zg) def sig(p): return "***" if p < 0.001 else "** " if p < 0.01 else "* " if p < 0.05 else " " # --- Summary: macro correlation per pipeline, raw and within-prompt --- print("=" * 80) print(f"{'PIPELINE':10s} {'n_raw':>5s} {'rawS':>7s} {'p(rawS)':>8s} {'n_zr':>5s} {'zS':>7s} {'p(zS)':>8s}") print("-" * 80) for key, idx in PIPES: rs = raw_spearman(idx, "agg_score_macro") zs, nz = zwithin_spearman(idx, "agg_score_macro") print(f"{key:10s} {len(rows):5d} {rs.statistic:+7.3f} {rs.pvalue:8.3g} {nz:5d} {zs.statistic:+7.3f} {zs.pvalue:8.3g}") print("=" * 80) print() # --- Sanity: cell-level agreement between the G-Vendi value sets --- pub_vals = [r[PUB] for r in rows]; repro_vals = [r[REPRO] for r in rows]; prx_vals = [r[PRX] for r in rows] print("=== Sanity: reproduction vs published (cell-level, raw G-Vendi) ===") print(f" Pearson rho(pub, repro) = {pearsonr(pub_vals, repro_vals).statistic:+.4f}") print(f" Spearman rho(pub, repro) = {spearmanr(pub_vals, repro_vals).statistic:+.4f}") print(f" mean(pub)={sum(pub_vals)/len(pub_vals):.4f} mean(repro)={sum(repro_vals)/len(repro_vals):.4f}") print() print("=== Sanity: base-proxy vs instruct-proxy (cell-level, raw G-Vendi) ===") print(f" Spearman rho(repro, prx06bb) = {spearmanr(repro_vals, prx_vals).statistic:+.4f}") print(f" mean(repro)={sum(repro_vals)/len(repro_vals):.4f} mean(prx06bb)={sum(prx_vals)/len(prx_vals):.4f}") print() # --- Per-metric correlation matrices (rows = metrics, cols = pipelines) --- def print_matrix(title, fn): print(title) print(f"{'metric':10s} {'pub':>11s} {'repro':>11s} {'prx06bb':>11s}") for col, short in SCORE_COLS: cells = [f"{(r := fn(idx, col)).statistic:+.3f}{sig(r.pvalue)}" for _, idx in PIPES] print(f"{short:10s} " + " ".join(f"{c:>11s}" for c in cells)) print("\n Significance vs rho=0: *** p<0.001, ** p<0.01, * p<0.05\n") print_matrix("=== Raw-pooled Spearman per downstream metric (n=83) ===", raw_spearman) print_matrix("=== Within-prompt z-scored Spearman per downstream metric (n=74) ===", lambda idx, col: zwithin_spearman(idx, col)[0])