AI Video Academy · How LLMs Work · intermediate

How Does Attention Work?

Queries, keys, values, and why each token looks back at earlier ones.

0:57 · captions in English · instrumental music, no narration

Transcript

How does a model know what a word like “it” refers to?

Each token makes a query, a key, and a value. Queries are matched against keys to decide which values to mix in.

Attention is the softmax of query-key scores, scaled and masked, applied to the values.

Each row shows how much one token attends to earlier tokens. Future tokens are masked.

Many attention heads run in parallel, each learning a different relationship.

Attention lets every token gather context from earlier tokens.

Experiment with this concept in PromptFlowEngine.