Model foundations · about 15 minutes of study

Attention

Attention combines token representations using weights computed from queries and keys. It helps a token use information from other allowed positions.

Before you start: Review Embeddings first. Python-like examples use variables, lists and functions.

Guided concept walkthrough

Follow the mechanism

Queries and keys

Compute compatibility scores for allowed positions.

1 / 4

A conceptual animation, not a live model trace. Play advances every five seconds and stops at the final stage.

Start with an everyday explanation

When reading a story, you look back to connect a pronoun to a character. This analogy explains selecting context, but a neural attention layer uses matrix operations rather than human understanding.

See a concrete example

For one head with two allowed positions and normalized attention weights 0.75 and 0.25, value vectors [2,0] and [0,4] combine to [1.5,1].

A claim to question

A bright attention connection does not prove causal reasoning or factual support.

Try before revealing the answer

Compute the weighted sum above, then mask out the second position and renormalize.

Show the worked answer

Without the second position, the first receives weight 1 and the result is [2,0]. Mask before softmax so disallowed positions receive no probability.

Now explain the idea to someone else using your own example. If you cannot explain a stage, revisit it before moving on.

Your explanation and revision notes

Loading local notes…

Read the primary reference

Attention Is All You Need

The explanation and exercises are original teaching material. The linked source provides background; examples and assumed numbers here are not claims about a particular company.