Foundations9 of 9

Why attention

Good predictions need the right earlier words, which can be far back. Attention lets every position look back at all earlier ones and pick what matters.

Play with it

Switch how much context the predictor may see, and watch whether it can get the verb right.

Thekeystotheoldwoodencabinet___
are
18%
is
82%

“cabinet” is singular, so a short window guesses “is”. The word that decides it is out of view. Illustration: hand-set numbers, not a real model.

The idea

“The keys to the old wooden cabinet ___”: the right verb is “are”, because of “keys”, six words earlier. A model that sees only the last word or two sees “cabinet” and guesses “is”.

Older recurrent networks (RNNs) read text one token at a time and squeezed everything so far into one fixed-size memory vector. Long-range details got lost, and they could not be trained in parallel.

Attention keeps every earlier token's vector around and lets the current position compute a weighted average of them, with the weights chosen by query-key matching. Distant tokens are one step away, and every position can be computed at the same time during training.

Don't confuse

Attention weights are not an explanation of the model's reasoning. They show where information was read from in one head of one layer, among hundreds.

Check yourself

What did attention replace, and what was that design's weakness?

Recurrent networks, which squeezed the whole past into one fixed-size vector, lost distant details and could not be parallelized across positions.

In a decoder-only LLM, which positions can a token attend to?

Itself and every earlier position, never later ones (the causal mask).

See your route