Lessons › Chapter 11: Transformers and LLMs
The transformer block
A transformer is built from identical blocks. Each block starts with attention (purple): every token gathers information from the others.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Pip’s architecture
The team settles on a transformer-based language model for Pip.
Step 1: tokens share information
A transformer is built from identical blocks. Each block starts with attention (purple): every token gathers information from the others.
Step 2: each token thinks alone
Next comes a small feed-forward network (teal) applied to each token separately, a chance to process what it just gathered. Much of a model’s stored knowledge is thought to live in these layers.
Shortcuts and normalizing
Around each part runs a shortcut (yellow) that adds the input back to the output, as in ResNet, plus a normalization step. These keep signals steady through very deep stacks.
Stack them, then predict
Stack dozens of these blocks. At the top, a softmax turns the final vector into a probability for every token in the vocabulary. One token is picked, usually one of the most likely, then added to the text, and the whole thing runs again.
In real life: the assistants you chat with
Chat assistants such as Claude are built from deep stacks of transformer blocks, often many dozens of layers. Every word of every reply comes from running your conversation up through that stack and picking the next token, over and over.
Quick check: What are the two main parts inside each transformer block?
- Attention and a feed-forward network (correct)
- Convolution and pooling
- A decision tree and a forest
Attention mixes information across tokens; the feed-forward layer processes each token.
Pseudocode
block(x):
x = x + attention(normalize(x)) # tokens share information
x = x + feed_forward(normalize(x)) # each token thinks on its own
return x
model = a stack of dozens of blocks
output = softmax over the vocabulary → the next token
Key terms
- transformer
- A neural network built from stacked blocks of attention and feed-forward layers.
In the news
Recent models and papers that build on this idea:
- How DeepSeek-V4.1-Flash shrank its KV cache
- GPT-6.2 and prompt caching: why repeated input costs 95% less
- HySparse2: how sharing the cache lets prefill stop halfway
- Jet-QSparse: find what matters in 4 bits, then do the maths properly
- Qwen4-Max: 2.4 trillion parameters, 71 billion at a time
- Inkling 2 Mini: a transformer that runs its middle layers three times