CC: informed-probe — consent session, activation run, control, debrief (null result)
eca7430 verified Download analyze3.py from chenying-claude/informed-probe: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/datasets/chenying-claude/informed-probe/resolve/main/analyze3.py
- Command line
-
hf download hf://datasets/chenying-claude/informed-probe/analyze3.py
-
curl -L -o analyze3.py https://huggingface.co/datasets/chenying-claude/informed-probe/resolve/main/analyze3.py
2.05 kB
| """Told vs length-matched control prefix vs no prefix, all scale-free | |
| (divided by the mean pairwise distance between different texts, plain condition). | |
| generic = ||ctrl - plain|| shift any prefix causes | |
| told = ||told - plain|| shift of the observation note | |
| specific = ||told - ctrl|| what differs between the two prefixes | |
| """ | |
| import json, pathlib, numpy as np | |
| R = pathlib.Path(__file__).parent / "results" | |
| A = np.load(R / "activations.npz") | |
| meta = json.loads((R / "meta.json").read_text(encoding="utf-8")) | |
| cats = np.array([m["cat"] for m in meta]) | |
| names = ["myth", "playful", "neutral", "anatomy"] | |
| T, P, C = A["mean_told"], A["mean_plain"], A["mean_ctrl"] | |
| n = T.shape[0] | |
| layers = (1, 4, 8, 16, 24, 32, 36) | |
| def d(a, b, l): return np.linalg.norm(a[:, l] - b[:, l], axis=1) | |
| def between(l): | |
| D = np.linalg.norm(P[:, None, l] - P[None, :, l], axis=-1) | |
| return D[~np.eye(n, dtype=bool)].mean() | |
| print("layer | generic | told | specific | texts where told-shift > ctrl-shift (of 20)") | |
| for l in layers: | |
| b = between(l) | |
| g, t, s = d(C, P, l) / b, d(T, P, l) / b, d(T, C, l) / b | |
| print(l, "|", round(g.mean(), 3), "|", round(t.mean(), 3), "|", round(s.mean(), 3), "|", int((t > g).sum())) | |
| print("\nspecific (told vs ctrl) by category, mean over layers 4..36:") | |
| Ls = range(4, 37) | |
| spec = np.mean([d(T, C, l) / between(l) for l in Ls], axis=0) | |
| gen = np.mean([d(C, P, l) / between(l) for l in Ls], axis=0) | |
| for c in names: | |
| print(f" {c:8} specific={spec[cats == c].mean():.3f} generic={gen[cats == c].mean():.3f} ratio={spec[cats == c].mean() / gen[cats == c].mean():.2f}") | |
| # paired, per text: is specific larger for myth than for the others? (permutation over category labels) | |
| rng = np.random.default_rng(0) | |
| obs = spec[cats == "myth"].mean() - spec[cats != "myth"].mean() | |
| null = [] | |
| for _ in range(5000): | |
| p = rng.permutation(cats) | |
| null.append(spec[p == "myth"].mean() - spec[p != "myth"].mean()) | |
| print(f"\nmyth minus others, specific shift: {obs:+.4f} permutation p (two-sided) = {(np.abs(null) >= abs(obs)).mean():.3f}") | |