Datasets:
Download code/two_way_interaction.py from Boesgaard/delivered-sooner: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/datasets/Boesgaard/delivered-sooner/resolve/main/code/two_way_interaction.py
- Command line
-
hf download hf://datasets/Boesgaard/delivered-sooner/code/two_way_interaction.py
-
curl -L -o two_way_interaction.py https://huggingface.co/datasets/Boesgaard/delivered-sooner/resolve/main/code/two_way_interaction.py
1.4 kB
| """Forward-minus-reverse MLP effect on sampled tokens (B - H) - (R - C), registered confirm.py draws. | |
| uv run --no-project --with numpy --with zstandard python code/two_way_interaction.py | |
| Output equals stats/audit/two_way_interaction.json. | |
| """ | |
| import json | |
| import sys | |
| from pathlib import Path | |
| import numpy as np | |
| sys.path.insert(0, str(Path(__file__).resolve().parent)) | |
| import confirm as cf # noqa: E402 | |
| from registered_draws_all_arms import PATHS, RAW # noqa: E402 | |
| dataset = RAW / "confirmation256/panel.jsonl" | |
| expected = {cf.item_key(r): r for r in cf.read_rows(dataset)} | |
| keys = sorted(expected) | |
| h = cf.fingerprint(dataset) | |
| arms = {k: cf.as_arrays(cf.verified_arm(PATHS[k], expected, h)[0], keys) for k in ("base", "all32", "reverse", "concise")} | |
| rng = np.random.Generator(np.random.PCG64(cf.SEED)) | |
| strata = {a: [i for i, k in enumerate(keys) if expected[k]["area"] == a] for a in cf.AREAS} | |
| draws = np.column_stack([rng.choice(m, size=(cf.DRAWS, len(m))) for m in strata.values()]) | |
| out = {} | |
| for metric in ("generated", "thinking"): | |
| b, f, r, c = (arms[k][metric].astype(float) for k in ("base", "all32", "reverse", "concise")) | |
| d = (b - f) - (r - c) | |
| out[metric] = {"forward_effect": float((b - f).mean()), "reverse_effect": float((r - c).mean()), | |
| "forward_minus_reverse": float(d.mean()), "ci": cf.interval(d[draws].mean(1))} | |
| json.dump(out, sys.stdout, indent=1) | |