Skip to content

Attention and head ablation

The model in the Model Explorer has learned that after the cat sat on the comes a place: mat or bed. That is not as easy as it sounds. Most of the time in its training sentences, “the” is followed by an animal, as in the dog or chased the cat. So something inside the model must notice that this “the” is different.

The model has two layers, each with two attention heads, and 4,496 trained parameters in all. Compare which head outputs affect that preference, then inspect what the heads read.

The interactive experiment uses JavaScript. If it does not appear, enable JavaScript or reload. You can also read how attention works.

Switching a head off sets that head’s output to zero before it is added back into the token’s vector. The input and other weights stay fixed, while downstream computations respond to the intervention. A collapse in the place prediction provides evidence that this head’s output is necessary under this intervention. This is called ablation; it does not by itself prove sufficiency or identify the entire mechanism.

What a head reads is its attention weights from the last word: how much of each earlier word’s information it takes in. The weights in each row add up to 1. The attention chapter explains where they come from.

The model learned from sentences generated by a small grammar: 4,000 training steps, each on 64 passages of 15 words. Every sentence starts with “the” or “a”, sometimes an adjective (big, small or red), and an animal (cat, dog or bird). Then it continues in one of five ways:

  • sat on or under the mat or bed (28% of sentences)
  • ran home, or ran to the mat or bed (18%)
  • slept (12%)
  • chased or saw another animal, such as “chased the small cat” (22%)
  • saw an animal and another animal (20%)

Each sentence ends with a full stop. About a third are followed by “then it” and a verb (sat, ran or slept), or “was” and an adjective, and another full stop.

The same grammar defines the model’s whole world: 25 words, and nothing outside these patterns.

Spotted a mistake, a confusing explanation or a broken widget? Report a problem with this page

Methods & evidence · Run locally

Free for noncommercial use. Text CC BY-NC-SA 4.0, code PolyForm Noncommercial. Source on GitHub · How to contribute