A probe that decodes a property from hidden states shows the information is there, not that the model uses it. Amnesic probing tests use by removal: find the directions a linear probe relies on, project them out of every hidden state, and measure what happens downstream. Iterative Nullspace Projection (INLP, Ravfogel et al.) repeats fit-and-remove until no linear probe can do better than chance. Removing one probe direction is the projection .
fit_probe(H, y): a least-squares linear classifier. H is (N, d), y an (N,) array of 0/1. Solve with targets , using np.linalg.lstsq on H with a column of ones appended and rcond=1e-10. Return (w, b) with w of shape (d,) and b a float.
probe_accuracy(H, y, w, b): the fraction of rows where agrees with y == 1, as a float.
nullspace_projection(directions, d): directions is a list of (d,) vectors (possibly empty, possibly not orthogonal or even parallel). Return the (d, d) orthogonal projection onto the subspace orthogonal to all of them: where the columns of are an orthonormal basis of their span (ignore singular values below times the largest).
inlp(H, y, max_iter=10, margin=0.05): start with . Each iteration: fit a probe on H @ P, record its accuracy rounded to 4 decimals; if the accuracy is at most the majority-class rate plus margin, stop; otherwise add the unit vector along to the directions and recompute from all directions so far. Return (P, directions, accuracies).
amnesic_effect(H, y_task, P, downstream): downstream is a function from an (N, d) array to (N,) predictions. Return (accuracy on H, accuracy on H @ P), each rounded to 4 decimals.
lstsq returns the minimum-norm one.