Mechanistic Interpretability: One Neuron, Two Features

Mechanistic interpretability on a small MNIST CNN: activation maximisation, dataset examples and ablation disagree about the same neuron.

Cover Image for Mechanistic Interpretability: One Neuron, Two Features

You've trained a network to recognise handwritten digits, and now you want to understand a prediction it made. Looking at the final label tells you little about which shapes the network used along the way. You can start with one unit in its last convolutional layer and examine the inputs that activate it. Mechanistic interpretability gives you ways to investigate that unit's behaviour and test how much it contributes to the network's decisions.

We investigate that unit with activation maximisation, matching inputs and ablation, using the earlier 2017 toolkit. The probes describe responses without tracing computation between units. At scale, Anthropic recovered millions of features from Claude 3 Sonnet in 2024. The laptop experiment tests what these probes can tell us.

Run all three on the same unit and they disagree. That disagreement is the useful part, and it appears on a convolutional network small enough to train on a laptop CPU. Behind it sits polysemanticity: a unit that fires hard for two things with nothing in common, because the network has more features to represent than it has channels to put them in.

By the end of this post you will have trained a small CNN on MNIST, run all three probes over its 32 last-layer units, found the one that fires for both zeros and twos, and measured how often the three probes name the same digit. On this network, over 31 live units, they all agree twice.

Let's Build It

Open this in Google Colab and run it top to bottom. Training takes about a minute on a CPU and every probe afterwards is inference-only.

Open In Colab

Here is unit 25 of the third convolutional layer, put to all three questions at once.

Three panels for conv3 unit 25. Left: the synthesised input from activation maximisation, a field of bright diagonal stripes, captioned that its nearest test digits are 4s. Middle: the nine test digits that activate the unit most strongly, three twos and six zeros. Right: a bar chart of accuracy lost per digit class when the unit is switched off, with the tallest bar on class 4 at 0.41 points.

Activation maximisation draws diagonal stripes. The dataset search returns zeros and twos. Ablation says the class that suffers most is 4. Three probes, one unit, three different answers.

The network is the one from Convolutional Neural Networks from Scratch, unchanged: three stride-2 convolutions of 8, 16 and 32 channels, one linear head, Adam at 10−310^{-3}, batch size 64, five epochs.

import torch, torch.nn as nn, torch.nn.functional as F
from torchvision import datasets, transforms

transform = transforms.Compose([transforms.ToTensor(),
                                transforms.Normalize((0.1307,), (0.3081,))])
train_data = datasets.MNIST('data', train=True, download=True, transform=transform)
test_data = datasets.MNIST('data', train=False, download=True, transform=transform)

class SimpleCNN(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(1, 8, kernel_size=5, padding=2, stride=2)   # 28->14
        self.conv2 = nn.Conv2d(8, 16, kernel_size=3, padding=1, stride=2)  # 14->7
        self.conv3 = nn.Conv2d(16, 32, kernel_size=3, padding=1, stride=2) # 7->4
        self.fc = nn.Linear(32 * 4 * 4, 10)

    def features(self, x, pre_relu=False):
        x = F.relu(self.conv1(x))
        x = F.relu(self.conv2(x))
        x = self.conv3(x)
        return x if pre_relu else F.relu(x)

    def forward(self, x):
        h = self.features(x)
        return self.fc(h.view(h.size(0), -1))

Five epochs of that reaches 98.5% on the test set, in 61 seconds on a MacBook CPU. Every probe below then runs in a few seconds, because none of them touches the weights again.

Epoch 1: 96.2% accuracy
Epoch 2: 97.7% accuracy
Epoch 3: 98.2% accuracy
Epoch 4: 98.2% accuracy
Epoch 5: 98.5% accuracy

You now have a system whose individual units can be interrogated with the tools people point at models a million times its size.

What Just Happened?

The unit under the microscope

A convolutional layer has no neurons in the dense-layer sense. Each of the 32 outputs of conv3 is a channel: one 3x3 filter applied at all 16 positions of a 4x4 grid. When this post says "unit 25", it means channel 25, and its activation on an image means the average of that channel over all 16 positions.

Five panels. A 28x28 input digit two, then three stacks of squares labelled conv1 14x14x8, conv2 7x7x16 and conv3 4x4x32, with one channel of the conv3 stack filled amber and labelled one unit equals one channel. The fifth panel shows the same digit with a 17x17 amber box over its top left corner, labelled what one conv3 position sees.

Stacking three stride-2 layers gives each conv3 position a 17x17 window on the input, stepping 8 pixels between neighbouring positions. That window matters later. When this post shows what excites a unit, it shows the 17x17 patch at the position where the unit fired hardest, because showing the whole digit lets the reader's eye fill in structure the unit never saw.

means, peaks, labels = [], [], []
with torch.no_grad():
    for batch, target in torch.utils.data.DataLoader(test_data, batch_size=500):
        acts = model.features(batch)                    # [B, 32, 4, 4]
        means.append(acts.mean(dim=(2, 3)))             # one number per unit
        flat = acts.view(len(batch), 32, 16).argmax(dim=2)
        peaks.append(torch.stack([flat // 4, flat % 4], dim=-1))
        labels.append(target)

mean_acts = torch.cat(means)      # [10000, 32]
peak_pos = torch.cat(peaks)       # [10000, 32, 2], where each unit fired hardest
labels = torch.cat(labels)

Probe 1: dataset examples

The cheapest probe sorts the test set by a unit's activation and looks at the top of the list. No optimisation, no synthesis, nothing that can hallucinate: these are inputs the network met in the wild.

order = mean_acts[:, 25].argsort(descending=True)[:100]
print(torch.bincount(labels[order], minlength=10))
# tensor([44,  1, 43,  4,  2,  0,  6,  0,  0,  0])

Of the hundred test images that excite unit 25 most, 44 are zeros and 43 are twos. A unit tuned to one digit would not produce that histogram. Unit 21, a few channels along in the same layer, gives [89, 0, 1, 1, 0, 0, 4, 0, 5, 0], the shape single-class tuning takes.

The probe has one weakness worth stating early. A ranked list tells you which inputs score highest, without saying whether the network uses that score for anything downstream.

Probe 2: activation maximisation

The second probe asks the network to draw its own answer. Start from noise, and run gradient ascent on the input while the weights sit frozen.

Animation over 12 frames of gradient ascent on the input image. The left panel starts as grey noise and resolves into three bright diagonal stripes on a dark background. The right panel plots unit 25 activation against step, an amber dot tracking along a curve that climbs steeply to step 50 and flattens by step 200.

img = torch.randn(1, 1, 28, 28) * 0.1
img.requires_grad_(True)
opt = torch.optim.Adam([img], lr=0.1)

for step in range(320):
    shift = torch.randint(-2, 3, (2,))
    jittered = torch.roll(img, tuple(shift.tolist()), dims=(2, 3))
    act = model.features(jittered, pre_relu=True)[0, 25].mean()
    loss = -act + 1e-3 * img.pow(2).mean()          # ascend, with a weak L2 pull
    opt.zero_grad(); loss.backward(); opt.step()
    with torch.no_grad():
        if (step + 1) % 4 == 0:
            img.data = blur(img.data, weight=0.3)   # kill high-frequency noise
        img.data = img.data.clamp(PIXEL_MIN, PIXEL_MAX)

Three details in that loop earn their place.

pre_relu=True is load-bearing. Score the post-ReLU activation and any unit sitting at zero for the initial noise has an exactly zero gradient, so it never climbs out. Written the obvious way, all 32 traces stay flat at 0.00 and every synthesised image is the regulariser's output. Optimising the pre-activation removes the trap.

The three regularisers keep the picture legible. Random jitter of up to two pixels before each forward pass stops the optimiser exploiting one exact pixel alignment. The L2 term pulls unremarkable pixels back towards the mean. The periodic blur suppresses the high-frequency checkerboard that unconstrained ascent always finds. Drop all three and the result is an adversarial example: high activation, no visible structure.

320 steps is enough and 60 is not. Unit 25 reaches 90% of its final activation at step 201 and wanders inside a narrow band afterwards, so the run ends shortly after it settles.

Set the result beside probe 1 before believing it. Unit 25's synthesised image is a set of diagonal stripes, while the inputs the unit prefers in the wild are zeros and twos. The picture is confident, legible, and it describes neither of them.

Probe 3: ablation

The third probe is the only causal one. Zero the channel, push the test set through, and measure what the network loses per class.

def per_class_accuracy(model, data, ablate=None):
    correct, total = torch.zeros(10), torch.zeros(10)
    with torch.no_grad():
        for images, labels in torch.utils.data.DataLoader(data, batch_size=1000):
            acts = model.features(images)
            if ablate is not None:
                acts = acts.clone(); acts[:, ablate] = 0.0
            preds = model.fc(acts.view(len(images), -1)).argmax(1)
            for cls in range(10):
                mask = labels == cls
                total[cls] += mask.sum(); correct[cls] += (preds[mask] == cls).sum()
    return correct / total

Ablating unit 25 costs 0.41 points on 4s, 0.19 on 2s, 0.10 on 0s, and gains a tenth of a point on 6s and 7s. The two classes that dominate its top-100 list are not the class that suffers most.

The first layer, where everything agrees

Before concluding that the probes are useless, run activation maximisation on conv1 and compare each result against the kernel it came from.

Two rows of eight panels. The top row shows the learned 5x5 kernels of the first layer as red and blue heatmaps. The bottom row shows the 5x5 input patch that gradient ascent settles on for each unit, in greyscale, with correlations of 0.91, 0.49, 0.91, 0.88, 0.85, 0.90, 0.85 and 0.90 against the matching kernel. Unit 1's 0.49 is marked in amber.

Seven of the eight first-layer units produce a patch correlating above 0.85 with their own kernel: bright pixels land where the weights are positive, dark where they are negative. At depth one the synthesised picture and the ground truth are the same object, which is why first-layer feature visualisations are so persuasive and why people extrapolate from them.

One catch applies here too. A convolution is linear before its ReLU, so maximising the mean over every spatial position drives all 784 pixels to the clamp and returns a saturated tile. Scoring a single position instead gives the 5x5 answer above.

Going Deeper

The disagreement, measured

Each probe can be reduced to a verdict: the digit class it names for a unit. The dataset probe names the most common class in the top 100. Activation maximisation names the majority class among the 25 test images most correlated with its synthesised pattern. Ablation names the class that loses the most accuracy.

Scatter plot over 31 conv3 units. For each unit, three markers show the digit class named by dataset examples, activation maximisation and ablation, joined by a vertical grey line. Most units show large vertical spread. Two units, 6 and 11, are shaded where all three markers coincide.

Across the 31 live units, dataset examples and ablation name the same digit for 4. Dataset examples and activation maximisation match on 12, and activation maximisation and ablation on 8. All three agree on 2. Averaged over the three pairings, two probes put to the same unit name the same digit about a quarter of the time.

Two failure modes drive this, and they are different from each other.

Redundancy, and what ablation can and cannot say

Ablation returns small numbers everywhere.

Heatmap of 32 units by 10 digit classes showing accuracy lost when each unit is switched off, in a red-blue diverging colour scale centred on zero. Most cells are near white. The largest cell, unit 31 on class 8, is circled and annotated at 1.75 points.

The worst single-unit cost anywhere in the grid is 1.75 points, on class 8, against a 98.49% baseline. The median unit's worst class loses 0.61 points. Read that alone and every unit looks unimportant, which cannot be true of all 32 at once.

The explanation is redundancy, and a group ablation shows it directly. Take every unit whose top-100 list is dominated by a given digit, switch the whole group off together, and compare against the same number of units picked at random.

Grouped bar chart for digits 0, 1, 2, 3, 5 and 7. For each, three bars: the mean single-unit cost, the cost of ablating the whole preferring group, and the cost of ablating the same number of random units. Digit 5 with 6 units loses 5.9 points as a group against 1.0 for random; digit 3 with 5 units loses 5.7 against minus 0.3; digit 0 with 10 units loses 4.4 against 1.2. Digits 1 and 2, with 3 and 2 units, show almost no group effect.

Six units prefer 5s. Removing any one of them costs 0.06 points on average, while removing all six costs 5.9, against 1.0 for six random units. The five units preferring 3s cost 5.7 points together, and a random five cost nothing measurable. Digits 1 and 2 have groups of three and two units and show no group effect, so the pattern needs a group of about five before it appears.

A single-unit ablation therefore measures how well the rest of the network copes without this unit. That is a real quantity, and it answers a different question from what the unit represents.

One neuron, two features

The second failure mode is the interesting one. Take the 100 receptive-field patches where a unit fired hardest and split them in two with k-means.

Four rows of image patches. The top two rows are unit 25: cluster 1 holds 53 patches, 81% of them zeros, all showing a rounded arc; cluster 2 holds 47 patches, 83% of them twos, all showing a flat base stroke meeting a diagonal. The bottom two rows are unit 21: both clusters, 59 and 41 patches at 85% and 95% zeros, show the same arc shape.

Unit 25 splits 53 to 47. One cluster is 81% zeros and holds a rounded arc; the other is 83% twos and holds the flat base stroke of a 2 meeting its diagonal. The two cluster means correlate at 0.41, and both clusters sit at the 99.6th percentile of that unit's activation range, so neither is a low-scoring tail.

Unit 21 is the control. Its two clusters are 85% and 95% zeros, both showing the same arc, and their means correlate at 0.79. k-means always returns two clusters, so the split alone proves nothing, and the claim rests on how far apart unit 25's two clusters sit compared with unit 21's. Ten of the 31 live units clear the same bar as unit 25: two balanced clusters, different dominant digits, both firing near the top of the range.

Elhage et al. (2022) named the mechanism. A layer with nn channels can represent nn features cleanly. Ask it to track more than nn and it stores them in superposition, as directions that are almost but not quite orthogonal, accepting a little interference in exchange for capacity. MNIST digits are built from more than 32 distinguishable strokes, so conv3 has to share.

This matters for probe 2 specifically. Gradient ascent maximises a scalar, so it finds one point, and a unit with two preferred inputs has at least two. The stripes unit 25 draws are a compromise between an arc and a corner, which is why they resemble neither.

The dead unit

One unit needs no interpretation at all.

Three panels for unit 7. Left: its synthesised image, a field of dark noise. Middle: its nine strongest test digits, all of which activate it by 0.00. Right: activation against gradient ascent step for unit 7, flat on zero, against unit 21 which climbs to about 5.

Unit 7 fires on none of the 10,000 test images. Its pre-activation moves from -0.689 to -0.663 across 320 steps of gradient ascent and never crosses zero. Activation maximisation still returns an image, because the optimiser always returns an image, and skimming a grid of 32 feature visualisations at thumbnail size would not pick this one out. Printing the activation value beside each picture catches it immediately.

Probe hyperparameters

KnobValue hereWhat moves if you change it
Ascent steps320Below ~200 the picture is still forming; above ~400 it only sharpens
Learning rate0.1Higher gets there sooner and lands on noisier images
Jitter±2 px0 gives pixel-aligned artefacts; above ~4 the image smears
L2 weight10−310^{-3}Raise it for cleaner, fainter images; too high and structure vanishes
Blur periodevery 4 stepsSkip it and high-frequency checkerboarding takes over
Top-k for the dataset probe100Below ~30 the class histogram is too noisy to read

The dataset probe's kk deserves care. At k=9k = 9, the size of a screenshot-friendly grid, unit 25 shows six zeros and three twos, which reads as a zero detector with noise in it. At k=100k = 100 the count is 44 against 43.

The limits of this method

Everything above is descriptive. It says what a unit responds to and what the network loses without it, and it says nothing about the computation that produced the response. No weight between two units has been examined. Circuits work begins exactly there, with Olah et al. (2020) tracing the connections between units instead of characterising units alone, and this post stops one step short of it.

Three further limits apply to the numbers here. The class-verdict readout compresses each probe into one digit, which is generous to units that respond to a stroke rather than a digit. The k-means split is fixed at two clusters, so a unit holding three features is scored as though it held two. And MNIST is a small, clean, ten-class problem, so the fraction of polysemantic units is a property of this network on this dataset.

Where This Comes From

Olah, Mordvintsev and Schubert introduced the modern form of probe 2 in "Feature Visualization" (Distill, 2017). For a chosen layer ll and channel cc, the objective is

x∗=arg⁡max⁡x  hl,c(x)x^{*} = \arg\max_{x} \; h_{l,c}(x)

where hl,ch_{l,c} is the mean activation of that channel. The paper opens on the same two options this post uses as probes 1 and 2:

If we want to understand individual features, we can search for examples where they have high values

Most of it then concerns what has to be added to the optimisation before its output is worth looking at. On the high-frequency patterns that unconstrained ascent produces, the authors are blunt:

These patterns seem to be closely related to the phenomenon of adversarial examples.

The jitter, blur and L2 term in the code above are their transformation-robustness and frequency-penalty families, in their simplest form.

Bau et al. published "Network Dissection" at CVPR the same year, with the opposite instinct: score each unit against a densely labelled concept dataset and report an intersection-over-union, instead of trusting a synthesised picture. Their finding that many units align with no single concept is the same observation this post reaches by clustering, arrived at three years before it had a name.

Timeline of five papers on a horizontal axis. Feature Visualization and Network Dissection in 2017, Zoom In: An Introduction to Circuits in 2020, Toy Models of Superposition in 2022 highlighted in amber, and Scaling Monosemanticity in 2024, each with a one-line note on what it contributed.

That name arrived with Elhage et al., "Toy Models of Superposition" (Anthropic, 2022). Their setting is a linear autoencoder squeezing nn sparse features through m<nm < n dimensions, and they show the network storing features as an over-complete, nearly orthogonal set once the features are sparse enough that collisions are rare. Their argument runs the direction this post travels in reverse: superposition is the cause and a unit responding to several unrelated things is the visible symptom. Unit 25 is one such symptom, in a network four orders of magnitude smaller than the ones the paper was written for.

The line from there to production runs through sparse autoencoders: Templeton et al. (2024) fit one to a middle layer of Claude 3 Sonnet and recovered millions of features, each closer to monosemantic than the raw units were. The three probes in this post are the 2017 toolkit, and the work since has been about the ceiling they hit.

Further Reading

  • Feature Visualization (Olah et al., 2017): read the "The Enemy of Feature Visualization" section for why regularisation is not optional
  • Zoom In: An Introduction to Circuits (Olah et al., 2020): the case for tracing weights between units instead of describing units one at a time
  • Toy Models of Superposition (Elhage et al., 2022): the formal account of why one unit ends up holding two features
  • Scaling Monosemanticity (Templeton et al., 2024): the same problem attacked with sparse autoencoders on a production model
  • Next: fit a small sparse autoencoder to these 32 activations and check whether the zero-arc and the two-base come apart into separate dictionary elements

Interactive Tools

  • 2D Convolution Visualizer: step a kernel across an input and watch the feature map fill in, the operation every probe here is inspecting
  • Overfitting Explorer: see how capacity relative to data changes what a network stores, the same trade-off that forces superposition

Stay in the loop

Get notified when new tutorials and deep-dives are published. No spam, unsubscribe anytime.

Related Posts

Frequently Asked Questions