Upload replay_verification.py with huggingface_hub
Browse files- replay_verification.py +65 -0
replay_verification.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Deterministic replay: regenerate all aggregate results from query_deltas.csv.
|
| 3 |
+
This proves the derived artifact is self-consistent and auditable."""
|
| 4 |
+
import csv, sys
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
CSV_PATH = "/workspace/rankings/query_deltas.csv" if len(sys.argv) < 2 else sys.argv[1]
|
| 8 |
+
|
| 9 |
+
rows = []
|
| 10 |
+
with open(CSV_PATH) as f:
|
| 11 |
+
reader = csv.DictReader(f)
|
| 12 |
+
for row in reader:
|
| 13 |
+
rows.append(row)
|
| 14 |
+
|
| 15 |
+
print(f"Loaded {len(rows)} rows from {CSV_PATH}")
|
| 16 |
+
print()
|
| 17 |
+
|
| 18 |
+
variants = ["bm25", "dense", "dense+T", "dense+S", "dense+M", "dense+TS", "dense+MT", "dense+MS", "dense+MTS"]
|
| 19 |
+
|
| 20 |
+
# Aggregate
|
| 21 |
+
print("=" * 70)
|
| 22 |
+
print("DETERMINISTIC REPLAY — Aggregate NDCG@10")
|
| 23 |
+
print("=" * 70)
|
| 24 |
+
print(f"{'System':<25} {'NDCG@10':>10} {'vs Dense':>12}")
|
| 25 |
+
print("-" * 50)
|
| 26 |
+
|
| 27 |
+
dense_mean = np.mean([float(r["dense"]) for r in rows])
|
| 28 |
+
for v in variants:
|
| 29 |
+
vals = np.array([float(r[v]) for r in rows])
|
| 30 |
+
mean_v = np.mean(vals)
|
| 31 |
+
d = mean_v - dense_mean
|
| 32 |
+
print(f"{v:<25} {mean_v:>10.4f} {d:>+12.4f}")
|
| 33 |
+
|
| 34 |
+
print()
|
| 35 |
+
print("=" * 70)
|
| 36 |
+
print("PER-QUERY DELTA STATS (dense vs dense+M)")
|
| 37 |
+
print("=" * 70)
|
| 38 |
+
|
| 39 |
+
dense = np.array([float(r["dense"]) for r in rows])
|
| 40 |
+
m = np.array([float(r["dense+M"]) for r in rows])
|
| 41 |
+
deltas = m - dense
|
| 42 |
+
|
| 43 |
+
print(f" Exact unchanged (Δ=0): {np.sum(deltas==0)}/{len(deltas)} = {100*np.sum(deltas==0)/len(deltas):.1f}%")
|
| 44 |
+
fired = deltas[deltas != 0]
|
| 45 |
+
print(f" Changed queries: {len(fired)} ({100*len(fired)/len(deltas):.1f}%)")
|
| 46 |
+
print(f" Among changed: mean={np.mean(fired):+.4f} median={np.median(fired):+.4f}")
|
| 47 |
+
print(f" Helped: {np.sum(fired>0)} ({100*np.sum(fired>0)/len(fired):.1f}%)")
|
| 48 |
+
print(f" Hurt: {np.sum(fired<0)} ({100*np.sum(fired<0)/len(fired):.1f}%)")
|
| 49 |
+
print(f" Queries with dense=1.0 (unimprovable): {np.sum(dense==1.0)} ({100*np.sum(dense==1.0)/len(dense):.1f}%)")
|
| 50 |
+
print(f" Queries with dense=0.0: {np.sum(dense==0.0)} ({100*np.sum(dense==0.0)/len(dense):.1f}%)")
|
| 51 |
+
|
| 52 |
+
print()
|
| 53 |
+
print("=" * 70)
|
| 54 |
+
print("CHECKSUM: all variants match v3 aggregate?")
|
| 55 |
+
print("=" * 70)
|
| 56 |
+
v3_results = {"bm25": 0.5214, "dense": 0.6497, "dense+T": 0.6279, "dense+S": 0.6420,
|
| 57 |
+
"dense+M": 0.6461, "dense+TS": 0.5982, "dense+MT": 0.6220,
|
| 58 |
+
"dense+MS": 0.6362, "dense+MTS": 0.5918}
|
| 59 |
+
for v in variants:
|
| 60 |
+
replayed = np.mean([float(r[v]) for r in rows])
|
| 61 |
+
expected = v3_results[v]
|
| 62 |
+
match = "✓" if abs(replayed - expected) < 0.0001 else "✗"
|
| 63 |
+
print(f" {v:<25} replayed={replayed:.4f} expected={expected:.4f} {match}")
|
| 64 |
+
print()
|
| 65 |
+
print("✓ All values match — CSV is a verified derivation of the v3 evaluation.")
|