Skip to content
mentoor

Topic 4 of 6 · 5 min read

Linear probes and activation steering

Goal: Design a linear probe experiment with a control that shows whether a concept is truly represented in the model.

A linear probe is a small classifier trained on a model's activations to test whether a concept can be read from them; steering goes the other way and adds a direction to change what the model does.

Check yourself · 1 of 3

A probe trained on shuffled labels still scores 85% on the test set. What does that tell you?

Choose one answer

Why it matters

Probes are cheap. You need activations, labels and a few lines of scikit-learn. But a probe can mislead: a strong classifier can find a pattern the model never uses. The method is only as good as its controls.

How to run a probe

  1. Choose the concept and labels, for example "sentence is true" vs "sentence is false", with a few thousand examples.
  2. Cache activations at one layer and one token position, such as the last token. TransformerLens does this for open-weight models.
  3. Split by source, not at random. If the same template or topic appears in train and test, the probe may learn the template.
  4. Fit a linear classifier (logistic regression) and report accuracy on the held-out split.
  5. Run controls (below).
from sklearn.linear_model import LogisticRegression
import numpy as np

X_train, y_train = acts["train"], labels["train"]
X_test, y_test = acts["test"], labels["test"]

probe = LogisticRegression(max_iter=1000).fit(X_train, y_train)
real = probe.score(X_test, y_test)

rng = np.random.default_rng(0)
shuffled = LogisticRegression(max_iter=1000).fit(X_train, rng.permutation(y_train))
control = shuffled.score(X_test, y_test)
print(real, control)

Controls that make a probe mean something

  • Shuffled-label control: the same probe trained on random labels should score near chance. If not, the probe is memorising.
  • Random-weights model: probe the same layer of an untrained model. If it scores nearly as high, the information is in the input encoding, not learned structure.
  • Selectivity: compare against a control task of similar difficulty with unrelated labels.
  • Keep it linear and simple. A deep probe can compute the concept itself.

Steering

To steer, take a direction, for example the difference between mean activations on "formal" and "casual" text, and add a multiple of it to the residual stream at one layer during generation. Too small has no effect, and too large breaks the text.

Before and after

Weak: "A probe reaches 96% accuracy at layer 12, so the model knows the statement is true." Better: "The probe reaches 96% on held-out topics, the shuffled-label control scores near chance, and adding the direction at layer 12 raises the rate of 'true' judgements."

What goes wrong

  • Decodable is not used. A concept that a probe can read need not influence the output. Steering or ablation tests use.
  • Confounds. Length, topic or format may track the label.
  • Probe leakage. Training and test examples share templates.

Examples

A probe that fails its control

A probe predicts sentiment at layer 4 with 91% accuracy. The same probe on a randomly initialised copy of the model scores 84%. Most of the signal is in the token embeddings, so the result says little about what the trained model learned at that layer.

Steering with a difference of means

direction = acts_formal.mean(0) - acts_casual.mean(0)

def hook(resid, hook):
    resid[:, :, :] += 4.0 * direction
    return resid

Adding the vector at layer 8 makes replies more formal. At a scale of 20 the output turns into repeated words, so the scale is part of the result you report.

Key points

  • A linear probe tests whether a concept can be read linearly from activations at a chosen layer and position.
  • Split train and test by source or topic, so the probe cannot score well by recognising templates.
  • A shuffled-label control and a random-weights model show whether high accuracy reflects learned structure.
  • Decodable does not mean used: only an intervention shows the model relies on the direction.
  • Steering adds a scaled direction to activations, and the scale needs tuning to avoid breaking the output.

Common mistakes

  • Reporting probe accuracy with no control and calling the concept represented.
  • Splitting at random when examples share templates or sources.
  • Using a deep non-linear probe, so the probe does the computation rather than reading it.
  • Assuming a concept that can be decoded is also used by the model.

Check yourself · 2 of 3

What does a high-accuracy linear probe at layer 12 show?

Choose one answer

Check yourself · 3 of 3

You want to test whether a probe's "truthfulness" direction is used by the model. What is the most direct test?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic