What this lesson covers.
This module is one of 42 in the curriculum. Below is the canonical interactive lesson — tabs, cards, and diagrams from the source repo, rendered inside the course shell. An audio narration runs alongside it - the sticky player at the top of the page plays the full Module 19 clip.
If you prefer to read first and play with the demos after, the interactive lesson sits below this section. If you'd rather hear it narrated while you scroll, hit play on the sticky audio bar at the top — or just let it autoplay.
Read / reason / test
Read the source while writing the output
High school · build the intuition
A decoder can use earlier output tokens and an encoded input as different information sources. In translation, the partially written translation is not the original sentence. Cross-attention connects those sequences, while causal self-attention governs the generated prefix. Keeping these paths distinct helps explain how a model can consult the source repeatedly without simply copying it word for word.
College · work the example
Five encoded input positions and three decoder positions produce a 3×5 cross-attention score matrix in one head. Decoder self-attention instead concerns 3×3 scores with future entries masked. Caching can reuse suitable past states, but the next output representation still requires computation. Matrix shape reveals which sequence supplies queries and which supplies keys and values.
Explain it back
Describe the process in your own words. Identify the assumption that makes this example work, then explain one conclusion it cannot establish.
Read the primary source or official documentation →
The numerical examples are authored teaching exercises, not measured model benchmarks. This extension adds context to the original lesson.
The lesson itself.
Inspector vs. Storyteller
Transformers process sequences differently based on their architecture. Encoders (like BERT) look at the entire sentence at once in both directions, making them great at analyzing text. Decoders (like GPT) are causally masked, meaning they can only see the past and must generate the future one word at a time, making them master storytellers.
The Inspector (Encoder)
Bidirectional Attention. Reads left-to-right AND right-to-left simultaneously.
The Storyteller (Decoder)
Autoregressive Causally Masked Attention. Only sees the past.
Further reading.
The canonical references for this module. External links open in a new tab.
What to read next.
Use the pager below to move sequentially through the curriculum, or jump to any module from the course index. Each track has a "Prereq: ↑ foundation" callout so you can backfill anything that wasn't clear.