Concept library/Transformers
10
8 minute interactive lab

The attention mechanism

Which tokens should influence this one?

YOU’LL LEAVE KNOWINGAttention builds a context-specific mixture of information.
THE EXPERIMENT

Let every token choose its context.

Move the controls. Watch the internal state respond. The explanation follows the behavior—not the other way around.

Runs the real small-scale equationThe displayed values are calculated from the formula shown in this lesson.
SCALED DOT-PRODUCT ATTENTIONChoose the token asking for context

it compares its query with every key. The dot products are divided by √d and normalized with softmax; all displayed weights sum to 100%.

The6.6%
server10.8%
returned7.4%
the6.6%
token19.9%
because7.0%
it18.5%
was6.9%
valid11.1%
.5.3%
largest non-self weight for “ittoken · score 1.32
THE MENTAL MODEL

Attention builds a context-specific mixture of information.

Each token creates a query and compares it with the keys of other tokens. The resulting scores become weights used to blend their values into context tailored to the current token.

IN DEVELOPER TERMScontext = softmax(query · keys) × values
GO DEEPER

Check the model against the source.

Connectionism optimizes for intuition, then points you to the rigorous treatment.

  1. Vaswani et al.Attention Is All You Need
  2. Jay AlammarThe Illustrated Transformer
YOU’VE FINISHED THE LIVE PATH

See what concepts are being built next.

Keep following the connections.

Return to the library