Learn the MachineDansk

Explained with an interactive demo

What is activation patching?

Activation patching is a method for finding out which parts of a model are actually used for a particular answer. You run the model on two almost identical prompts, move one internal value from one run to the other, and measure how much the answer changes. Try it yourself on a small model below.

The demo needs JavaScript. The text below explains what it shows.

Embed this demo on your site

Copy the code into your page. The demo loads from learnthemachine.com, so it stays up to date, and the link under it shows where it comes from.

The idea: a controlled experiment

Looking at an activation tells you what the model computes. It does not tell you whether the model uses it. Activation patching is a controlled experiment: two prompts that differ in only one detail, and one intervention at a time. Everything else is the same, so any change in the answer must come from the value you moved.

How it is done

  1. Pick a clean prompt and a corrupted prompt that differ only in the information you want to trace. Here it is the city.
  2. Pick a metric, usually the logit difference between the correct answers for each prompt.
  3. Run both prompts and save every activation.
  4. Run one prompt again, but replace one component’s activation with its value from the other run. Everything after that component is computed as normal.
  5. Measure what share of the difference the patch moves: (patched − baseline) / (target − baseline).

Repeat step 4 for every component, for example every attention head in every layer and every position, and you get a map of where the information lives. The table at the bottom of the demo is a small version of that map.

What the demo shows

The city token restores 100%, because all the information about the city comes from it. Head C restores 0%, because it is the same in both prompts. The MLP restores 92%; the rest takes a direct path from head A to the output that bypasses the MLP.

The interesting one is head B. Insert its clean value into the corrupted run and it restores 70%. Remove it from the clean run and it changes only 5%, because head A on its own is enough to push the MLP over its threshold. Head B is a backup. That is why the two directions say different things: inserting clean values tests whether a component is enough to bring the answer back, and inserting corrupted values tests whether the model needs it. Real models often have backups like this, and a result from only one direction can mislead.

What a result does not show

An effect holds for the model, the prompt pair and the intervention you chose. It does not prove that a component represents a particular concept, and a patch can create combinations of activations the model never normally sees. Effects of two components do not always add up either: try patching heads A and B separately and then together. That is why you repeat the experiment on many pairs and use controls: with no patch you should get the baseline, and patching everything should give the target.

Patch a network you trained yourself

In the Activation patching lab you train a small network in the browser, patch its hidden neurons, measure the effect in logits and check your interventions with controls. Afterwards you can go on to patch an attention head in the Transformer lab. Both labs require full access.

See the Activation patching labStart free with Vectors and neurons

More explainers