insideout Get Pro

06 · What trained heads learn

Pro

Transformers, lesson 6

What trained heads learn

Previous-token, induction and other patterns found in real models.

This builds on "Heads in parallel": each layer runs many attention heads side by side, and each head has its own row of weights for every token.

Part 1. Reading an attention pattern

Researchers can run a trained model on some text and record every head's weights. For one head, that gives a grid: one row per token doing the looking, one column per token being looked at. Because of the causal mask, everything above the diagonal is zero.

Example 1.1

One head's weights on "the cat sat on the mat"

  1. cat:the 0.92cat 0.08

    Read one row at a time. The row for "cat" says where "cat" took its information from: almost all of it came from "the".

  2. sat:the 0.03cat 0.90sat 0.07

    The row for "sat" puts its weight on "cat". Again, the word right before it.

  3. on:sat 0.88
    the:on 0.91
    mat:the 0.89

    Every row does the same thing, whatever the words are. On the grid, that draws a bright stripe one step left of the diagonal. (These weights are illustrative.)

Attention pattern

The grid of one head's weights over a piece of text. Reading patterns is the most common first step when people try to work out what a head does.

Your turn

Which pattern would you expect from a head whose job is "copy in the word right before me"?

Row i puts its weight on column i − 1, which is a stripe just below the diagonal. That's a previous-token head. They're among the easiest heads to spot, and researchers have found them in many trained models, from tiny ones to large ones.

Part 2. Heads that continue a pattern

Keep going with Pro

You've done the first part. Pro opens the rest of this lesson, and every other one.

Still to come
  1. Heads that continue a pattern
  2. Heads that park on the first token
  3. What patterns don't tell you

Transformers overviewSpotted a mistake? Tell us.