mej7.comHow AI Works

Mechanistic Interpretability

Lesson 1 of 4 · Mechanistic Interpretability level · interactive visualization (simplified teaching model)

MECHANISTIC INTERPRETABILITY

Look inside: which words does the model attend to?

Real transformers use "attention" to decide, for every word, how much to look at every other word. This is a toy inspired by real attention; the values do not come from a trained model. Type a sentence and see which tokens light up for each other.

SELF-ATTENTION · TOY MODEL

Rows are "query" tokens, columns are "key" tokens; brighter cells mean stronger attention weight (softmax over a toy scoring function keyed on token content and distance). Real attention heads are learned from data and often specialize — one head might track subjects and verbs, another might track punctuation. This toy version is for intuition, not a real model's internals.

Toy model for intuition, not real model weights.

What you are seeing

You type a short sentence. The page splits it into tokens and draws a grid. Each row is a query token, the token that is "asking". Each column is a key token, a token it might look at. A brighter cell means a larger attention weight after softmax. The weights in a row are meant to be read as a distribution: they are positive and, in a real head, they sum to one.

In the transformer picture used by mechanistic interpretability, this grid is the output of the QK circuit. Queries and keys produce a score, the score is masked so a token cannot look at the future, and softmax turns scores into weights. The grid does not show the other half of the head. It does not show what information is copied. That is the OV circuit, and the value-mixing lab is the place on MEJ7 that draws the copying step.

What is simplified here

The scores are not Q and K from a trained model. They come from a fixed teaching rule that looks at the tokens' content and at how far apart they are. Nothing on this page was learned by gradient descent. There is one head, not the many heads of a real layer. There is no residual stream underneath the grid, so you cannot see the update being added back onto a running vector. The disclaimer under the grid says the same thing in shorter form: brighter means stronger weight under that toy rule.

A real attention pattern is often sparse and oddly specific. Published work has found heads that mostly look at the previous token, heads that copy a repeated pattern (induction heads), and heads that do not have a clean role a person can name. This toy cannot discover those, because there is nothing to discover. If you change the sentence, the grid changes because the rule is reapplied, not because a circuit recognized the sentence.

How this relates to real models

Researchers still start with a picture like this one. They cache the attention pattern of a real head with a library such as TransformerLens, then they ask a causal question: if this pattern is scrambled, or if the head is ablated, does the behaviour break? The pattern alone is not the explanation. Indirect object identification in GPT-2 small is a full circuit of several heads, not one bright cell. Induction is a pair of heads, not a single row of the grid.

Read the key concepts pages on attention heads, induction heads, and circuits. The papers to open next are A Mathematical Framework for Transformer Circuits and In-context Learning and Induction Heads, both on the reading list. When you want the same picture on a real model, use TransformerLens and, for the drawing layer, CircuitsVis. This page is the intuition you should have before those tools. It is not a substitute for them.