Log inStart free
LESSON 10.09 · 6 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

Encoder-only, decoder-only and encoder–decoder

Follow one sentence through BERT-, GPT- and T5-style transformers.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 2 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 10.09 · FAMILY BAYGPT-STYLE · 1 STACK · CAUSAL MASK
01
Stage 1 of 6 · The stacks
A GPT-style decoder-only model has one stack. Each output row predicts the next token.
Explain it simply

On the left you see one box, the decoder stack. The six words go in at the bottom. On top, each position guesses the word that comes next. Chat models like GPT work this way.

One decoder stack with causal self-attention and an MLP. Six tokens go in; each output predicts the next token. On the right, three cards name the families; decoder-only is picked.

Weights are random, not trained. The toy runs only the attention parts.
tokens, targetsattention weights, outputsweightschange after a new tokenblocked cell
decoder stackMLPcausal self-attentionthecatsatonamatnext token at every rowone stackBERT-style · encoder-onlyreads both sides · sorting, tagging, searchGPT-style · decoder-onlyreads earlier tokens · chat, code, writingT5-style · encoder–decoderinput in, output out · translation, summariesthree families1 stack · 6 tokens in · 6 rows outdecoder stackMLPcausal self-attentionthecatsatonamatnext token at every rowone stackBERT-style · encoder-onlyreads both sides · sorting, tagging, searchGPT-style · decoder-onlyreads earlier tokens · chat, code, writingT5-style · encoder–decoderinput in, output out · translation, summariesthree families1 stack · 6 tokens in · 6 rows out
Toy: 6 tokens · width 4 · one head, one layer per stack
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
yi=xi+attention⁡(x)i\sy{y}{out}{y_i} = \sy{x}{data}{x_i} + \operatorname{attention}(\sy{x}{data}{x})_i
stacks=1: decoder (6 tokens)\text{stacks} = 1:\ \text{decoder} \ (6 \text{ tokens})

Each output row adds the attention result to its token vector.

Common mix-ups

MYTHBERT can write text one token at a time, like GPT.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01In an encoder-only model, how many tokens can row "sat" read?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 2 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.