Train a linear probe on hidden states, train the same probe on a control task to measure how much is memorisation, and then test whether moving a hidden state along the probe direction changes a downstream read-out.
train_probe(H, y, steps, lr, l2=0.0)
H is (N, d), y an (N,) array of 0/1. Logistic regression with weights w (d,) and bias b initialised to zero, trained by full-batch gradient descent on the mean log loss plus l2 * ||w||^2 / 2. Return (w, b).probe_accuracy(H, y, w, b)
(H @ w + b > 0) == (y == 1), as a float.control_labels(y, rng)
rng.permutation(y).selectivity(H, y, rng, steps, lr, l2=0.0, decimals=4)
rng.permutation call), return a dict with "probe_acc", "control_acc" and "selectivity" (their difference), rounded.intervene(h, w, alpha, readout)
h + alpha * w / ||w||, and return (readout(h_new) - readout(h)) as a float, where readout is a callable from a (d,) vector to a scalar.H.T @ (sigmoid(z) - y) / N for w and the mean residual for b.steps and lr for the real and the control probe; only the labels differ.