Linear probes
线性探针
Freeze features, solve a readout and separate accessible information from causal use and leakage.
linear-probesStart with the problem
A feature may contain a label without making it easy to read. The signs of two coordinates determine an XOR-style class, but a straight decision boundary cannot perfectly separate the four corner cases. Adding their product exposes the same label to a linear readout.
A linear probe freezes a representation and trains only a simple readout. Alain and Bengio use independent softmax classifiers on hidden layers, preventing probe gradients from changing the model. This asks how accessible a target is to that readout, not whether the original model actually uses the target in making decisions. Understanding intermediate layers using linear classifier probes — arXiv v1
We use a squared-loss linear score so its optimum can be checked by a direct solve. That is a declared alternative to the paper’s cross-entropy classifier. Two supplied feature maps, three disjoint input grids and a label-permutation control make the experimental boundaries explicit.
Definitions and derivation
Let be fixed features. Estimate means and standard deviations on the training set only; append a constant column for the intercept. Denote the resulting design matrix by H and binary target scores by y, either −1 or +1. Our probe is:
Penalize feature weights but not the intercept. For diagonal R with ones on feature entries and zero on its last entry:
Set this gradient to zero to obtain the exact ridge readout. Select lambda by validation score error, then evaluate once on the test grid:
A positive lambda makes the feature block strictly penalized; the intercept remains identified by its nonzero constant column. Forming the normal matrix costs and a dense solve costs for d design columns. For high-dimensional or ill-conditioned features, QR/SVD or iterative solvers may be preferable to explicitly forming normal equations.
Our expanded map is . It is provided by the experiment designer, not claimed to have emerged through unsupervised training. Freezing is what lets different readouts evaluate the same representation without turning the experiment into fine-tuning.
Run the calculation
Use CPython 3.12.4 and NumPy 1.26.4. Training, validation and test each have 16 points with distinct coordinate magnitudes. Both probes select lambda 0.01. The raw-feature ridge probe reaches 50% test accuracy; the product-feature probe reaches 100%, with score MSE 0.336817959. These linear scores are not calibrated probabilities and may exceed one. The 50% result belongs to this squared-loss optimum; it is not an upper bound over all possible linear decision rules. One hundred independent row-label permutation controls average 0.5025 accuracy.
import numpy as np
def grid(values):return np.array([(a,b) for a in values for b in values],dtype=float)
def features(x,expanded=False):return np.c_[x,x[:,0]*x[:,1]] if expanded else x.copy()
def fit(train,labels,regularization=.01):
mean=train.mean(axis=0);scale=train.std(axis=0);scale=np.where(scale<1e-12,1,scale);h=np.c_[(train-mean)/scale,np.ones(len(train))];penalty=np.diag([regularization]*(h.shape[1]-1)+[0.]);w=np.linalg.solve(h.T@h/len(h)+penalty,h.T@labels/len(h));return mean,scale,w
def predict(model,x):
mean,scale,w=model;return np.c_[(x-mean)/scale,np.ones(len(x))]@w
def labels(x):return np.where(x[:,0]*x[:,1]>0,1.,-1.)
def experiment(expanded=False):
train=grid([-1.,-.5,.5,1.]);validation=grid([-.8,-.2,.2,.8]);test=grid([-1.2,-.6,.6,1.2]);y=labels(train);chosen=None
for lam in (.01,.1,1.):
model=fit(features(train,expanded),y,lam);mse=float(np.mean((predict(model,features(validation,expanded))-labels(validation))**2))
if chosen is None or mse<chosen[0]:chosen=(mse,lam,model)
score=predict(chosen[2],features(test,expanded));accuracy=float(np.mean(np.where(score>=0,1,-1)==labels(test)));return chosen[1],accuracy,float(np.mean((score-labels(test))**2)),chosen[2]
if __name__=='__main__':
for expanded in (False,True):
lam,accuracy,mse,model=experiment(expanded);print('features',('x1,x2,product' if expanded else 'x1,x2'),'validation-selected lambda',lam,'test accuracy',accuracy,'test score MSE',round(mse,9))
train=grid([-1.,-.5,.5,1.]);test=grid([-1.2,-.6,.6,1.2]);rng=np.random.default_rng(19);scores=[]
for _ in range(100):
model=fit(features(train,True),rng.permutation(labels(train)),.01);control_test=rng.permutation(labels(test));scores.append(np.mean(np.where(predict(model,features(test,True))>=0,1,-1)==control_test))
print('independent row-label permutation control mean accuracy',float(np.mean(scores)),'trials',len(scores))
features x1,x2 validation-selected lambda 0.01 test accuracy 0.5 test score MSE 1.0
features x1,x2,product validation-selected lambda 0.01 test accuracy 1.0 test score MSE 0.336817959
independent row-label permutation control mean accuracy 0.5025 trials 100
When the method fails
Probe accuracy mixes properties of the representation, the readout family, regularization, data size and optimization. A weak probe can fail to read information that is present nonlinearly. A powerful probe can memorize incidental structure. High accuracy does not establish that the original model uses a feature causally; that requires a different intervention-based investigation.
Hewitt and Liang introduce control tasks in which randomly assigned behavior is consistent for each word type, and compare task accuracy with control accuracy. Our independent row-label permutations are a simpler sanity check; they do not implement those word-type controls or establish linguistic selectivity. Designing and Interpreting Probes with Control Tasks
Split by the actual unit of independence—such as person, document or time series—before extracting samples. Fit normalization on training data only and tune probe choices on validation data. If the encoder already saw the test labels during pretraining or model selection, freezing it now does not undo that leakage. Report layer, pooling, dimensions, regularization, labeled sample count and test protocol with every probe score.
Exercises with answers
- Does a failed linear probe prove a label is absent from the representation?
Answer 1: No. The label may require a nonlinear readout; the product construction gives one example.
- Which parameters can change during a frozen probe experiment?
Answer 2: The readout parameters; the encoder is held fixed. Training normalization statistics belong to the fitted probe pipeline.
- Why is the 50% ridge result not a universal bound on linear classification of XOR?
Answer 3: Squared error and classification accuracy optimize different objectives. On the four corners, a line can classify three of four correctly, though no line separates all four.
- Are the 100 row-permutation runs the word-type controls of Hewitt and Liang?
Answer 4: No. Those controls preserve a random behavior per word type; our row permutations test a simpler random-label baseline.
Sources and next steps
Read Alain and Bengio’s Section 3.1 for frozen softmax probes and the distinction between information and accessibility. Then read Hewitt and Liang’s control-task construction rather than borrowing its name for any shuffled-label test. Continue with embedding evaluation to compare retrieval, classification and domain-level reporting; one probe score does not summarize all uses of an embedding. Understanding intermediate layers using linear classifier probes — arXiv v1; Designing and Interpreting Probes with Control Tasks
Make a prediction, then check
A label is predictable by a frozen linear probe. What does that establish?
Learning objectives
- Fit a readout without modifying features or using test statistics.
- Interpret a probe together with its objective and control design.
Prerequisites & connections
Explore related knowledge →References
- Understanding intermediate layers using linear classifier probes — arXiv v1
Guillaume Alain; Yoshua Bengio · 2016 - Designing and Interpreting Probes with Control Tasks
John Hewitt; Percy Liang · 2019
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-07 · Codex single-AI-author technical check: primary-source scope, explicit assumptions, original calculations, independent mathematical references and bilingual tests; not independent human or second-agent review.
- Single-AI-author technical check: bounded primary-source reading, explicit assumptions, original calculations, executable examples and corresponding bilingual equations, code and exercises. Not independent human or second-agent review.
- Four CPython 3.12.4 checks per chapter: spectra and exact recurrence with scale-aware tolerances, frozen ridge probes, literal graded retrieval metrics, whitening/SVD constraints, finite balancing marginals and stopped targets, pseudo-label denominator, exact noise expectation and temperature-weighted distillation as applicable, plus bilingual structure. All eight programs use NumPy 1.26.4; no real image/text benchmark reproduction claimed.
- Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
Source locations checked:
- Understanding intermediate layers using linear classifier probes — arXiv v1 · Version 1 physical page 4, Section 3.1 and Figure 2: frozen model, stop-gradient, softmax cross-entropy probe; our squared-loss variant explicitly distinguished.
- Designing and Interpreting Probes with Control Tasks · Physical pages 2–3, selectivity and Section 2 word-type-consistent random control tasks; row-permutation baseline not claimed equivalent.
Related topics