Probing: Asking a Frozen Model What It Knows

You have a big pretrained model and a few hundred labels. Freeze the model, turn each example into a vector, and train a tiny classifier on the vectors. That tiny classifier is a probe. Its score tells you what the model already knows, and often it is the whole product.

Learn why a linear probe gives a fair, repeatable score, why scaling the features can move a score from 1 to 18, and how a probe that is too clever fools you.

Pick a backbone and a probe. Slide the number of labels. Then switch on the control task, which gives every word a random label. A probe that still scores well is memorising, not reading.

You need a rough idea of vectors and of training by gradient descent. We build the rest from zero.

Probe a frozen model

Ready
96
0.001

A toy you can train. The points are a made-up 2-D view (like PCA) of frozen embeddings: 48 words, each seen in 8 sentences, so each tight cluster is one word. Half of each word's points train the probe; the other half test it. The control task follows Hewitt and Liang (2019): each word gets one random label Hewitt & Liang · §2. All accuracies are computed live in this page.

Chapter 0

Why probe?

Meet the problem a probe solves, its two jobs, and the three answers it can give you

You work at a wildlife charity. You have 300 recordings from forest microphones, and a volunteer has marked which ones contain a woodpecker. You also have a large audio model that someone else trained on two million clips. It has never heard the word "woodpecker".

Does that model already "know" woodpeckers? You cannot ask it in words. But you can do something simpler. Run every clip through the model, keep the vector it produces, and see whether a very small classifier can tell woodpecker vectors from the rest.

That small classifier is a probe: a small model trained on the frozen features of a big model, to read out one property. Frozen means the big model's weights never change. Only the probe learns. The big model is called the backbone, and the vector it outputs for one example is its embedding or feature vector.

One block, two jobs

  1. Grade a representation. Papers on self-supervised learning train a backbone without labels. To show it learned something, they freeze it and report linear-probe accuracy on a labelled benchmark. The probe is the measuring tape.
  2. Build a cheap classifier. The woodpecker detector is just the probe. It trains in seconds on a laptop, needs few labels, and the expensive backbone is shared by every task you build.

The data flow is the same for both jobs. A batch of B clips goes into the backbone. Out come B vectors of D numbers each, a B × D matrix. The probe maps that to B × C scores, one per class. Nothing flows back into the backbone.

Three properties, three answers

The same 400 embeddings, coloured by three different properties. Pick a property. A linear probe (a straight line) and a kNN probe (a vote of neighbours) both try to read it.

Illustrative 2-D embeddings. Both probes train on 200 points and are scored on the other 200. The shading is the kNN probe's decision; the line is the linear probe's.

Those are the three answers a probe can give. The property is linearly readable: a straight cut separates it, and a linear probe finds it. The property is there but curved: only a more flexible probe finds it. Or the property is absent: no probe finds it, because the backbone threw it away or never saw it.

The idea in one line: freeze the big model, train a tiny one on its vectors, and read the tiny one's held-out score as "how easily this property can be read from these features".

This lesson builds the probe from zero and answers five questions about it, in plain words:

  1. The linear probe: logistic regression on embeddings, with the loss and gradient derived.
  2. One right answer: why the loss is convex, and why that makes the score fair.
  3. Regularize, then cross-validate: L2 shrinkage and how to choose its strength.
  4. Scale the features first: standardize or LayerNorm, and the AudioFM collapse.
  5. The kNN probe: no training, cosine against Euclidean, and the choice of k.
  6. MLP probes and control tasks: when a probe learns the task itself.
  7. Cover's theorem: why 768 numbers make almost anything linearly separable.
  8. Which layer to probe: why the middle often beats the top.
  9. Build it in PyTorch: cache features once, then three ways to train.
  10. Did it work?: learning curves, shuffled labels, confusion, leaks, and the gap to fine-tuning.
  11. Where else, and when not: five fields, a decision table, and the cheat sheet.
What changes while you train a probe?

Chapter 1

Why it works: the linear probe

Build logistic regression on embeddings from a weighted sum, derive its loss and gradient, and step it by hand

Start with two classes: woodpecker or not. Each clip is a feature vector x of D numbers. The simplest reader of x is a weighted sum. Give each feature a weight, add them up, and add a constant. Call the result the logit z. A large positive z means "woodpecker"; a large negative z means "not".

We want a probability, not an unbounded score. The sigmoid function squeezes any number into the range 0 to 1. So the probe is:

x
The frozen feature vector of one example: D numbers from the backbone.
w
The probe's weights: one number per feature. These are learned.
b
The bias: one learned number that shifts the cut.
σ
The sigmoid: maps any logit to a probability between 0 and 1.
p
The probe's probability that this example is in the positive class.

Worked: x = (2, 1), w = (0.5, −1), b = 0 → z = 1 − 1 = 0 → p = σ(0) = 0.5. The probe is unsure.

The decision boundary is where p = 0.5, so where w · x + b = 0. In two dimensions that is a line. In D dimensions it is a flat sheet, a hyperplane. That is why we call this probe linear: it can only cut the feature space with one flat cut per class.

The loss: punish confident mistakes

How wrong is p? If the true label is y = 1, we want p near 1. If y = 0, we want p near 0. The cross-entropy loss is minus the log of the probability the probe gave to the true answer:

y
The true label: 1 or 0.
p
The probe's probability for class 1.
L
The loss for one example. Near 0 when confident and right; very large when confident and wrong.

Worked: y = 1. p = 0.9 → L = −log 0.9 = 0.105.   p = 0.5 → L = 0.693.   p = 0.01 → L = 4.6

The gradient: (p − y) times x

To learn, we need the slope of L with respect to each weight. Use the chain rule in three short steps. First, the derivative of the sigmoid is σ(z)(1 − σ(z)), which is p(1 − p). Second, the derivative of L with respect to p is −y/p + (1 − y)/(1 − p). Multiply the two, and almost everything cancels:

p − y
The error: how far the predicted probability is from the label. Positive if the probe said "yes" too strongly.
x
The features. Each weight moves in proportion to its own feature's value.
w
Update rule: w ← w − η(p − y)x, with step size η, averaged over the batch.

Worked: x = (2, 1), y = 1, p = 0.5 → gradient = (0.5 − 1)(2, 1) = (−1, −0.5). With η = 0.1: w = (0.5, −1) + (0.1, 0.05) = (0.6, −0.95). Now z = 0.25 and p = 0.56: closer to 1.

Step the probe by hand

The probe starts at w = 0, so p = 0.5 for every point. Press Step to take one gradient step with the rule above. Press Run for 100 steps. Try a large step size.

0.50

Illustrative 2-D features, 120 points. Full-batch gradient descent on the mean cross-entropy, exactly the update in the equations above.

More than two classes

With C classes, the probe keeps one weight vector per class. Stack them into a matrix W of shape D × C. The logits for a batch are X W + b: (B × D) times (D × C) gives B × C. The softmax turns each row into C probabilities that sum to 1: pc = ezc / Σk ezk. The same algebra gives the same gradient: the error (p − onehot(y)) times x. For a batch, ∂L/∂W = XT(P − Y) / B, a D × C matrix, the same shape as W.

A probe gives p = 0.8 for an example whose label is y = 0, with features x = (1, 3). What is the gradient of the loss with respect to w?

Chapter 2

Why it works: one right answer

Show that the linear probe's loss is a bowl with a single bottom, and see why that makes its score fair and repeatable

Suppose two labs probe the same backbone. Lab A reports 71.3%. Lab B reports 69.8%. Is the backbone good or not? If the probe's training can end in different places, the difference may be luck: the random start, the order of batches, when training stopped. A score you cannot reproduce is a poor measuring tape.

The linear probe avoids this problem. Its loss is convex: shaped like a bowl, with no false bottoms. Any path downhill reaches the same lowest value. So every lab that trains long enough gets the same probe and the same score.

The bowl, in one second derivative

A function is convex when its curvature is never negative. Take the derivative of the gradient (p − y)x once more. Only p depends on w, and its derivative is p(1 − p)x. So the curvature matrix, the Hessian, is:

H
The Hessian: a D × D matrix of second derivatives. It says how the slope changes as w moves.
p(1 − p)
Always between 0 and 0.25. Never negative.
x xT
An outer product. For any direction v, vT(x xT)v = (v · x)2 ≥ 0.
λI
The L2 term from Chapter 3. With λ > 0 the bowl is strictly curved in every direction, so the bottom is a single point.

Every term is a non-negative number times a non-negative square. So the curvature is never negative in any direction, and the loss is convex.

Worked, one feature: x = 2, p = 0.5 → curvature = 0.5 × 0.5 × 22 = 1 > 0. At p = 0.99 it is 0.0099 × 4 = 0.04: still positive, just flatter.

Six starts, one bottom?

Each line is one training run from a different random start. Pick a probe and press Train. Do the six runs end at the same loss?

Illustrative data: two interleaved crescents, 160 training points. Both probes use a small L2 term (λ = 0.01). The MLP has 6 hidden units and trains with Adam. Everything is computed in this page.

The linear runs start far apart and land on the same loss, within about 0.001. The MLP runs land in different valleys with different held-out scores. That spread is noise in the measurement, not a property of the backbone.

Why do self-supervised papers usually report a linear probe, not an MLP probe?

Chapter 3

Why it works: regularize, then cross-validate

Add an L2 penalty that keeps the weights small, see it trade training accuracy for held-out accuracy, and let cross-validation pick its strength

Real probes often have more features than labels. A 768-d embedding and 50 labelled clips gives 769 numbers to fit from 50 examples. The probe can then fit the training set perfectly, using noise in features that mean nothing. That is overfitting: perfect on training data, worse on new data.

The fix is to make large weights cost something. L2 regularization adds the squared length of w to the loss:

J(w)
The objective the probe minimises: data fit plus a penalty.
λ
The regularization strength. 0 means no penalty; large means "keep w near zero at almost any cost".
‖w‖2
The sum of the squared weights. The bias is not penalised.

Worked: w = (3, −2), λ = 0.1, η = 0.5 → the penalty's part of the step is −ηλw = (−0.15, +0.10). Each step shrinks w by 5% before the data pulls it back. That is why L2 is also called weight decay.

Too little λ overfits. Too much λ ignores the features and predicts the most common class. The best value depends on the data, so we must measure it, without touching the test set.

Cross-validation

k-fold cross-validation splits the training labels into k equal parts, the folds. For each candidate λ, train on k − 1 folds and score on the one left out. Rotate so every fold is left out once, and average the k scores. Pick the λ with the best average. Then retrain on all the training labels with that λ. The test set is used once, at the very end.

Choose λ without peeking

50 features, of which 8 carry a weak signal. Drag λ. The blue curve is 5-fold cross-validation on the training labels only; the grey line is the test score you would not normally see. Change the number of labels.

0.001

Illustrative data: two classes whose means differ by 0.38 in each of 8 features; 42 more features are pure noise. The best any classifier can do is about 84%. Each point is a logistic regression trained in this page; test accuracy uses 1,500 fresh points.

Three lessons hide in that plot. With few labels, training accuracy is 100% at every small λ: it tells you nothing. Cross-validation is noisy with 30 labels, so the λ it picks is only roughly right. And the right λ shrinks as labels grow, because data itself starts to restrain the weights.

A probe with 768 features and 40 labels scores 100% on its training labels at every small λ. What should you use to choose λ?

Chapter 4

Scale the features first

See how badly scaled features stall gradient descent, compare standardization with LayerNorm, and read a real collapse from the AudioFM paper

Here is a real result that surprises most people. The AudioFM paper froze six audio backbones and trained the same linear probe on each, on AudioSet-20K, a benchmark of 527 sound classes. Two strong backbones, EAT and SSLAM, scored about 1 mAP. That is close to random guessing. Then the authors put a LayerNorm in front of the same probe. The scores jumped to about 18 AudioFM · Table 3.

Backbone (frozen)Bare probe, mAPLayerNorm probe, mAPFine-tuned, mAP
AudioMAE13.911.935.5
EAT1.118.740.5
SSLAM0.918.239.3
BAT18.128.540.3
AudioMosaic28.733.441.8
AudioFM31.235.042.3

AudioSet-20K. Probe columns: AudioFM Table 3, means over three seeds. Fine-tuned column: Table 2; the five baselines were re-fine-tuned by the AudioFM authors on their AudioSet-20K split. mAP (mean average precision) averages, over classes, how well the scores rank true clips above false ones.

So EAT's features held the information all along. With fine-tuning EAT reaches 40.5. The bare probe simply could not use the features as they came. The paper reports this without explaining it. The most likely culprit is scale, and the next toy shows the mechanism.

Why scale breaks gradient descent

Gradient descent uses one step size η for every weight. Chapter 2 showed the curvature along feature j is about p(1 − p) times the average of xj2. A feature with values near 200 has curvature 40,000 times larger than one with values near 1. Gradient descent is stable only if η is below 2 divided by the largest curvature:

η
The step size, shared by all weights.
κmax
The largest curvature in any direction. Steps larger than 2/κmax overshoot and bounce.
mean(xj2)
The average squared value of feature j. Big features make big curvature.

Worked: a feature of scale 200 → κ ≈ ¼ × 40,000 = 10,000 → η < 0.0002. A useful feature of scale 1 has κ ≈ 0.25, so each step moves it about 0.0002 × 0.25 = 0.00005 of the way. It needs about 20,000 times more steps.

Either the step is small enough for the big feature, and the small useful features barely move. Or it suits the small ones, and the big feature makes training bounce. A fixed probe recipe gets one of the two.

Two ways to rescale

Standardization rescales each feature across the dataset: zj = (xj − μj) / σj, where μj and σj are the mean and spread of feature j over the training set. LayerNorm rescales each example across its features: subtract the mean of that vector's D numbers and divide by their spread, then apply a learned scale and shift per feature. They fix different problems.

Same probe, three scalings

Pick what is wrong with the raw features. The bars show each feature's spread on a log scale. Press Train: the same recipe (step size 0.1, 300 steps) runs on raw, standardized and LayerNormed features.

A toy, not the paper's data: 8 features, 2 of them useful, 200 training and 1,000 test points. "Shared offset" adds about 60 to every feature, with a per-example gain, like a loudness level. "One giant" multiplies one useless feature by 150. The paper does not say what goes wrong inside EAT and SSLAM; this shows two mechanisms that can sink a bare probe.

Standardization fixes both toy problems. LayerNorm fixes the shared offset, because it removes each vector's own mean and scale. It fails on the single giant feature, because that one feature dominates every vector's spread. So the safe default is to standardize with training-set statistics. Use LayerNorm when you want the probe to match papers that use it, as AudioFM's "flexible" probe does AudioFM · Table 3.

EAT scores 1.1 mAP with a bare linear probe and 18.7 with a LayerNorm probe. What is the best reading?

Chapter 5

The kNN probe

Classify by a vote of the nearest labelled examples, choose between cosine and Euclidean distance, and pick k

A linear probe still trains: it needs a step size, a number of steps and a λ. There is a probe with no training at all. Store every labelled feature vector. For a new example, find the k stored vectors nearest to it and let them vote. That is the k-nearest-neighbour probe, or kNN probe.

It measures something different from a linear probe. It asks: are examples of the same class close together in this space? That is local neighbourhood structure. It is what matters for search and retrieval, where you look up similar items by distance.

Which distance?

Two choices dominate. Euclidean distance is the straight-line length between two vectors. Cosine similarity compares only directions:

a · b
The dot product: the sum of ajbj over all features.
‖a‖ ‖b‖
The two lengths. Dividing by them removes length, leaving only the angle.
cos(a, b)
1 for the same direction, 0 for perpendicular, −1 for opposite. â is a divided by its length.

Worked: a = (3, 4), b = (6, 8) → a · b = 50, ‖a‖‖b‖ = 5 × 10 = 50 → cos = 1. Same direction. Their Euclidean distance is still 5.

The second identity says cosine kNN is just Euclidean kNN after scaling every vector to length 1. So the question is: does the length of your vectors carry meaning, or nuisance? In many backbones, length tracks things like loudness, contrast or how common a word is. Cosine ignores it.

Who are your neighbours?

Here the class lives in the direction of a vector; its length is loudness, a nuisance. The labelled clips were all recorded loud; new clips come at every volume. Drag the white query point. Change k and the distance.

9

Illustrative 2-D features: 160 stored labelled points with lengths 0.6 to 1, scored on 400 new points with lengths 0.04 to 1. The origin is the bottom-left corner. The shading is the probe's decision everywhere.

Choosing k

Small k trusts single neighbours, so one mislabelled or odd example can flip a decision. Large k averages over a wider area and blurs real boundaries; at the extreme, it predicts the most common class everywhere. Like λ, choose k by cross-validation. The DINO paper swept k and found 20 neighbours "consistently working the best" for its ImageNet evaluation DINO · §4.1. There, a kNN probe on a small ViT reached 74.5% against 77.0% for a linear probe DINO · §4.1.

Two embeddings point the same way but one is twice as long. Which statement is true?

Chapter 6

MLP probes and control tasks

Give the probe a hidden layer, watch it learn the task itself, and measure that with a control task and selectivity

If a linear probe scores 85%, why not add a hidden layer and score 90%? A multilayer perceptron (MLP) probe does that: features go into a hidden layer of H units with a non-linearity, then a linear layer. Its shapes are D → H → C. It can draw curved boundaries, so it often scores higher.

But think about what you wanted to measure: what the backbone knows. A probe with enough capacity can learn the task itself, from almost any features, by memorising. Then a high score says more about the probe than about the features.

The control task

Hewitt and Liang (2019) turned this worry into a measurement Hewitt & Liang · §2. They probed word vectors for part-of-speech tags: noun, verb, and so on. Then they built a control task. Each word type gets one random tag, kept the same everywhere that word appears. "Dog" might always be tag 17, whatever the sentence.

No linguistic knowledge helps with the control task. The only way to score well is to recognise each word and memorise its random tag. So a probe's control-task score measures how much it can memorise. Their selectivity is the gap:

task accuracy
Held-out accuracy on the real labels.
control accuracy
Held-out accuracy on random-per-word labels: same inputs, same label set, no meaning.
selectivity
High when the probe reads real structure and cannot just memorise.

Their numbers, ELMo layer 1, part-of-speech: linear 97.2 task, 71.2 control → selectivity 26.0. MLP with 1,000 hidden units: 97.3 task, 92.8 control → selectivity 4.5 Hewitt & Liang · Table 1

The MLP gained 0.1 points on the task, and almost all of its accuracy could come from memorising. The linear probe was nearly as accurate and far more selective. Train both yourself:

How much does the probe memorise?

60 word types with 10-d features; each word appears 6 times. Press Train: probes from linear up to 64 hidden units learn the real tags and the control tags. Then slide to inspect one probe.

linear

A toy in the paper's setting, not its data. Real tags depend on two directions in feature space; control tags are random per word. 4 occurrences per word train the probe; the other 2 test it. The MLPs use tanh and Adam, 400 steps. Computed in this page.

Hewitt and Liang also found that the usual fix, dropout, did not reliably restore selectivity. Smaller hidden layers did: MLPs with just 10 hidden units, fewer training examples, or weight decay were selective and almost as accurate Hewitt & Liang · §1, Table 1.

A probe scores 95% on a task and 93% on its control task. What do you conclude?

Chapter 7

Why it works: Cover's theorem

Count how many labelings a flat cut can produce, find the sharp edge at twice the dimension, and learn what high-dimensional separability does and does not mean

Why do linear probes work so often on big embeddings? And why can a linear probe memorise random labels? Both answers come from one counting result by Thomas Cover (1965).

Take N points in D dimensions, in general position: no three on a line, no four on a plane, and so on. Give each point a label, 0 or 1. There are 2N possible labelings, called dichotomies. How many of them can a flat cut separate perfectly? Cover counted them exactly. For a cut through the origin in d dimensions:

C(N, d)
The number of labelings of N points that some hyperplane through the origin separates.
(N−1 choose k)
The number of ways to choose k items from N − 1.
d
For a probe with a bias, use d = D + 1: the bias acts like one extra feature fixed at 1.

Worked: 4 points in a plane, with a bias → d = 3 → C(4, 3) = 2 × (1 + 3 + 3) = 14 of the 24 = 16 labelings. The 2 missing ones are the "XOR" patterns, where opposite corners share a label.

Divide by 2N to get the chance that a random labeling is separable. Two facts fall out. If N ≤ d, every labeling is separable: the chance is exactly 1. And at N = 2d, the chance is exactly one half. Around that point the chance drops from nearly 1 to nearly 0, more sharply as d grows.

Can a flat cut fit random labels?

The curve is Cover's formula. Pick the feature dimension D and the number of points N. Press Test to draw 40 sets of random points with random labels and check each with a perceptron.

5
12

Points are Gaussian, so they are in general position. A labeling counts as separable if the perceptron with a bias reaches zero training errors within 3,000 passes; near the edge it can miss a few separable cases, so dots may sit slightly below the curve.

What this means for a 768-d probe

A linear probe with a bias on 768-d features has d = 769. So any 769 examples, with any labels, can be fit perfectly. Even at 1,538 examples, half of all random labelings fit. Three consequences follow.

  1. Training accuracy is meaningless when N is not much larger than 2D. Only held-out accuracy counts.
  2. A linear probe can memorise too, when labels are few. That is why its control-task score in Chapter 6 was well above chance.
  3. High dimension helps real classes. Cover's own motivation: map inputs into many dimensions with a non-linear map, and structured classes become linearly separable. A backbone does exactly this, with a learned map.
You have 500 labelled examples and 1,024-d features. Your linear probe reaches 100% training accuracy. What does Cover's theorem say?

Chapter 8

Which layer to probe

Probe every layer of a network, see why the best layer is often in the middle, and know when the top layer wins

A backbone is a stack of layers, and every layer outputs a vector. Which one should the probe read? The habit is to take the last one. Often that is not the best choice.

A layer-wise probing curve answers the question with data. Extract features at every layer, train the same probe on each, and plot held-out accuracy against depth. The shape of that curve tells a story about how the network builds and drops information.

A probing curve you can compute

A 10-layer network with fixed random weights reads a 2-D point. A linear probe reads each layer. "Which side" is visible in the raw input; "Same sign" (an XOR) is not. Add noise per layer to model information being lost.

0.08

A real computation on a toy: input (u1, u2), a random 2-to-24 map, then 10 random tanh layers of width 24 with Gaussian noise added after each. Each layer's probe is logistic regression trained on 300 points and tested on 800. Real networks drop information by training, not by added noise; the noise is a stand-in.

Two forces shape the curve. Early layers build combinations: "same sign" is not readable from the raw input but becomes readable after a non-linear layer. That is Cover's idea from Chapter 7 at work. Deeper layers drop what they do not need. In a trained network, the top layers specialise in the pretraining objective, such as predicting the next word or a masked patch. Properties that objective does not need fade away.

What real networks show

The rule that ties these together: the top layer is best for the task the network was trained on. For any other task, sweep the layers. Common shortcuts are to probe the average of a few middle layers, or to learn one weight per layer and mix them.

You probe a self-supervised speech model for speaker identity and get the best score at layer 4 of 12. What is the most sensible reading?

Chapter 9

Build it in PyTorch

Trace the shapes from raw input to logits, cache the features once, then train the probe three ways: by hand, from scratch, and with one library call

The most important engineering fact about probing: the backbone is frozen, so its output for a given input never changes. Run it once over your data and save the features. Every probe you train afterwards reads that saved matrix. A hundred epochs of probe training then cost a hundred passes over a small matrix, not a hundred passes through a large network.

Shapes through the pipeline

Pick a frozen backbone and slide the dataset size and number of classes. Every box shows the shape that flows through it.

10,000
10

Backbones are the DINOv2 family (Oquab et al., 2023): embedding sizes 384, 768, 1,024 and 1,536, about 21M, 86M, 300M and 1.1B parameters. Images are 224 × 224 RGB. Cache sizes assume 32-bit floats.

Step 1: cache the features

pythonimport torch
from torch.utils.data import DataLoader

@torch.no_grad()                                  # no graph, no gradients: the backbone is frozen
def extract(backbone, dataset, batch_size=64, device="cuda"):
    backbone.eval().to(device)                    # eval(): dropout off, norm statistics fixed
    feats, labels = [], []
    for x, y in DataLoader(dataset, batch_size=batch_size):
        f = backbone(x.to(device))                # x: (B, 3, 224, 224) -> f: (B, D), D = 768
        feats.append(f.float().cpu()); labels.append(y)
    return torch.cat(feats), torch.cat(labels)    # (N, D) float32 and (N,) int64

backbone = torch.hub.load("facebookresearch/dinov2", "dinov2_vitb14")
# train_set / test_set: torchvision datasets with Resize(256), CenterCrop(224), ToTensor, Normalize
Xtr, ytr = extract(backbone, train_set)
Xte, yte = extract(backbone, test_set)
torch.save({"Xtr": Xtr, "ytr": ytr, "Xte": Xte, "yte": yte}, "feats.pt")

Two details matter. @torch.no_grad() stops PyTorch from storing activations for a backward pass, which cuts memory several times. And eval() fixes dropout and normalization, so the same image always gives the same vector. Forget it, and your "frozen" features change from run to run.

Step 2a: the library one-liner

pythonimport numpy as np, torch
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV

d = torch.load("feats.pt")
Xtr, ytr = d["Xtr"].numpy(), d["ytr"].numpy()     # (N, D), (N,)
pipe = make_pipeline(StandardScaler(),               # per-feature mean/std, refit inside every fold
                     LogisticRegression(max_iter=3000))
search = GridSearchCV(pipe, {"logisticregression__C": np.logspace(-4, 2, 13)}, cv=5)
search.fit(Xtr, ytr)                                 # 13 values of C x 5 folds, then refit on all
print("best C:", search.best_params_)
print("held-out accuracy:", search.score(d["Xte"].numpy(), d["yte"].numpy()))

Putting the scaler inside the pipeline matters. Then cross-validation refits the scaler on each fold's training part only, so no statistics leak from the held-out fold. Remember from Chapter 3: C = 1 / (λN).

Step 2b: from scratch in PyTorch

pythonimport torch, torch.nn as nn, torch.nn.functional as F

class LinearProbe(nn.Module):
    def __init__(self, dim, n_classes):
        super().__init__()
        self.norm = nn.LayerNorm(dim)             # per-vector rescale (AudioFM's "flexible" probe)
        self.fc = nn.Linear(dim, n_classes)       # weight (C, D), bias (C,)
    def forward(self, f):                         # f: (B, D) cached features
        return self.fc(self.norm(f))              # logits: (B, C)

d = torch.load("feats.pt")
Xtr, ytr = d["Xtr"], d["ytr"]
probe = LinearProbe(Xtr.shape[1], int(ytr.max()) + 1)
opt = torch.optim.AdamW(probe.parameters(), lr=1e-3, weight_decay=1e-4)  # decoupled weight decay, close to L2
for epoch in range(100):
    for idx in torch.randperm(len(Xtr)).split(256):  # mini-batches of cached rows
        logits = probe(Xtr[idx])                  # (256, C)
        loss = F.cross_entropy(logits, ytr[idx])  # softmax + minus log-probability of the true class
        opt.zero_grad(); loss.backward(); opt.step()  # fc.weight.grad = (P - Y)^T f / B
with torch.no_grad():
    acc = (probe(d["Xte"]).argmax(1) == d["yte"]).float().mean()
print(f"held-out accuracy {acc:.3f}")

Read the shapes once more. The weight of nn.Linear(D, C) is stored as C × D, the transpose of our W. F.cross_entropy takes raw logits and does the softmax itself, so never apply a softmax before it. The gradient in the last comment is Chapter 1's (p − y)x, written for a batch. Pick the number of epochs, the learning rate and the weight decay on a validation split, never on the test set.

Step 2c: the kNN probe

pythonimport torch, torch.nn.functional as F

def knn_probe(Xtr, ytr, Xte, k=20, T=0.07):
    n_classes = int(ytr.max()) + 1
    A, B = F.normalize(Xtr, dim=1), F.normalize(Xte, dim=1)  # unit length: dot = cosine
    sim = B @ A.T                                 # (Nte, Ntr) cosine similarities
    top, idx = sim.topk(k, dim=1)                # (Nte, k) best matches and their rows
    w = (top / T).exp()                           # closer neighbours vote louder
    votes = torch.zeros(len(Xte), n_classes)
    votes.scatter_add_(1, ytr[idx], w)           # add each neighbour's weight to its class
    return votes.argmax(1)                      # (Nte,) predicted classes

For large N, compute sim in chunks of test rows, so the Nte × Ntr matrix never sits in memory at once. The weighted vote with a temperature T follows the DINO-style kNN evaluation; k = 20 is the value DINO found best DINO · §4.1, and T = 0.07 is a common choice.

You run 100 epochs of probe training on 50,000 images. With cached features, how many times does the backbone see each image?

Chapter 10

Did it work?

Read a learning curve, run the shuffled-label check, read a confusion matrix, catch a leak, and interpret the gap between probing and fine-tuning

A single probe number hides a lot. Five checks turn it into evidence. Each takes minutes once the features are cached.

Learning curves and the shuffle test

A learning curve plots held-out accuracy against the number of labels. Train each probe on 2, 4, 8 … labels per class. The curve shows how label-efficient the features are: good features reach a high score with few labels. It also shows whether more labels would still help.

The shuffled-label test is the cheapest sanity check in machine learning. Shuffle the training labels, so they no longer match the inputs, and retrain. Held-out accuracy must fall to chance. If it does not, something leaks: a bug in the split, a label hidden in the features, or test data in training.

Learning curves, shuffle, confusion

Three classes in 16-d features; two of them overlap. Each curve point is a probe trained with that many labels per class. Turn on Shuffle labels. The grid is the linear probe's confusion matrix at the largest size.

Illustrative data. Linear: logistic regression, λ = 0.01. kNN: Euclidean, k = 5. MLP: 32 hidden units, λ = 0.001. Scored on 600 held-out points; computed in this page.

A confusion matrix has one row per true class and one column per predicted class. Off-diagonal cells show which classes the features mix up. Here, B and C trade errors while A is clean. That tells you where more labels, or a better backbone, would help.

Leakage: the silent score inflator

Probe data often comes in groups: many 1-second windows from one recording, many slices from one patient's scan, many frames from one video. Members of a group look alike for reasons unrelated to the label: the same microphone, the same scanner, the same room. If one window of a recording is in training and its sibling is in test, the probe can match the recording, not the class.

Split by window, or by recording?

80 recordings, 6 windows each. Every recording has its own "fingerprint" in the features, plus a weak class signal. Compare a random split of windows with a split that keeps each recording on one side.

1.5

Illustrative data: 12-d features = recording fingerprint + small window noise + a weak class direction. Half the windows (random split) or half the recordings (group split) train; the rest test. kNN uses k = 1, cosine; linear uses λ = 0.01.

The fix is a group split: assign whole recordings, patients or videos to one side. scikit-learn's GroupKFold does it for cross-validation. Note who suffered most in the toy: the kNN probe, which found each window's sibling. A big drop from random to group split is a sign the old score was a leak.

The gap to fine-tuning

Finally, compare the probe with fine-tuning, which trains the backbone too. The gap between the two tells you how much the task needs the features to change. On AudioSet-20K, AudioFM's LayerNorm probe scores 35.0 and fine-tuning 42.3; EAT's scores are 18.7 and 40.5 AudioFM · Tables 2, 3. A small gap means the information is there and linearly readable, and the probe may be all you need. A large gap means the information is there in a form the probe cannot read, or the task needs features the pretraining never made. Then a richer head or partial fine-tuning pays off.

You split windows randomly and get 94%. Splitting by recording gives 61%. Which score do you report, and why?

Chapter 11

Where else it works, and when not to use it

Move the same probe across five fields, decide when another block wins, and keep the whole lesson on one screen

The probe is the same block everywhere: frozen features in, a small readout out. What changes from field to field is what goes in, how the features are pooled, the shape of the output, and the metric. Step through five fields.

Same probe, five fields

Pick a field. The diagram shows the input, the frozen backbone, the feature shape, the probe and the metric. The readout says what changes and what stays.

Shapes are typical examples, not requirements: AudioSet has 527 classes; DINOv2 ViT-B and BERT-style models give 768-d vectors; a 7B-parameter LLM typically has 4,096-d hidden states.

FieldFeaturesProbeWhat to watch
Audio eventsa clip vector from CLAP or AudioFM, mean-pooled over timelinear + one sigmoid per class (multi-label)scaling (Chapter 4); short events vanish in a mean, so try attention pooling
Medical imagesa CLS vector from DINOv2 or a chest X-ray model such as RAD-DINOlinear, softmax or sigmoidsplit by patient, not by image; few labels make the learning curve essential
LLM hidden statesthe residual stream at one layer, last tokenlogistic regression: true or false statement, positive or negative sentimentsweep layers (Chapter 8); a control task, because a probe can key on surface words
Robot policythe policy's vision features for one camera framelinear regression to the object's (x, y), mean squared errorif position is not readable, the policy may be guessing from the scene, not the object
Satellite mapsone geospatial embedding per pixel or patchthe same linear map at every location (a 1 × 1 convolution)neighbouring pixels leak into each other; split by region

For LLM truthfulness, see Azaria and Mitchell (2023), "The Internal State of an LLM Knows When It's Lying", and Marks and Tegmark (2023), "The Geometry of Truth". Both train simple probes on hidden states. In interpretability, a probe asks is this concept represented here?, and selectivity and controls matter most. In applications, a probe asks is this good enough to ship?, and held-out accuracy on honest splits matters most.

When not to use it

SituationWhat happensUse instead
The features do not contain the property (wrong modality, random or unrelated backbone)No probe finds it; the learning curve stays flat near chancefine-tune, or a backbone trained on related data: adapters and fine-tuning depth
Classes need non-linear combinations and labels are fewLinear underfits; an MLP overfitsa kNN probe, or a small MLP checked with a control task
Many labels, and a task far from pretrainingThe probe-to-fine-tune gap stays largepartial fine-tuning, LoRA or adapters
The event is short inside a long inputMean-pooling dilutes it before the probe sees itan attention-pooling head
Train and test share recordings, patients or regionsThe score is inflated by leakagea group split, always

The cheat sheet

PartIn one line
BlockA frozen backbone, cached features, and a small trained readout.
Shape signature(B, D) → linear (D, C) → (B, C) logits; MLP adds (D, H) and (H, C).
Mathsp = softmax(xW + b); loss = cross-entropy + λ/2‖W‖2; gradient XT(P − Y)/B + λW; convex.
Knobsλ (or C = 1/(λN)) by cross-validation; scaling (standardize or LayerNorm); layer; k and distance for kNN; H for MLP.
Checkslearning curve, shuffled labels, control task, confusion matrix, group split, gap to fine-tuning.
Failure modesbad scaling, memorising probes, leaky splits, wrong layer, information not present.
AlternativeskNN probe, attention pooling, adapters and LoRA, full fine-tuning.

Where this sits, and where to go next

Probing is the simplest member of a family. This lesson belongs to the Builder's Toolkit series, which starts at Backbone and head. Next: attention-pooling heads learn which frames to read, and adapters and fine-tuning depth let the backbone move. Background on the site: logistic regression, linear classifiers, regularization, bias and variance, normalization, high-dimensional geometry, PCA, transfer learning, self-supervised learning, contrastive learning, metric design, the PyTorch training loop and interpretability. Papers: AudioFM (the probe collapse), DINO and DINOv2 (kNN and linear evaluation), CLAP.

Honest limits. A probe measures how easily a property can be read, with one probe family, from one layer, with your labels. It does not show that the model uses the property; that needs interventions, such as editing the features and watching the output. And a probe score is only as good as the split behind it.

The takeaway. Freeze, cache, scale, and fit a linear probe with λ chosen by cross-validation. Read its held-out score beside a shuffled or control baseline, on an honest split, at the right layer. Reach for kNN, an MLP or fine-tuning only when those checks say you should.
You probe a robot policy's features for the target object's position and get an R2 near 0 on held-out frames, while the policy succeeds. What is a sound next step?

Now press Present or Teach and explain, out loud and from memory, why a linear probe gives a fair score and how a probe can fool you. Then go back to the hero, pick the Random backbone, and explain why the MLP still scores well there.

Sources: Hewitt and Liang, "Designing and Interpreting Probes with Control Tasks", EMNLP 2019 (arXiv:1909.03368). Li, Zhang, Wang, Fonseca, Ellis et al., "AudioFM: Towards General Purpose Audio Representation Learning", 2026 (arXiv:2610.34183), Tables 2 and 3. Cover, "Geometrical and Statistical Properties of Systems of Linear Inequalities with Applications in Pattern Recognition", IEEE Trans. Electronic Computers, 1965. Alain and Bengio, "Understanding intermediate layers using linear classifier probes", 2016 (arXiv:1610.01644). Liu, Gardner, Belinkov, Peters and Smith, "Linguistic Knowledge and Transferability of Contextual Representations", NAACL 2019 (arXiv:1903.08855). Skean et al., "Layer by Layer: Uncovering Hidden Representations in Language Models", ICML 2025 (arXiv:2502.02013). Caron et al., "Emerging Properties in Self-Supervised Vision Transformers" (DINO), ICCV 2021 (arXiv:2104.14294).
Back to Gleams