techtree / Transformer
Stacking blocks
The same block design, repeated many times, each with its own weights.
Transcript
One block makes one round of edits to the token vectors. A transformer stacks many blocks, one on top of the next. What comes out of one block goes into the next.
Every block has the same design, but its own weights: its own attention matrices, and its own MLP.
The residual stream runs up through all of them. Each block reads the vectors, and adds its edit.
Small models have about a dozen blocks. The largest have around a hundred.
Early blocks tend to pick up simple patterns, like which words sit nearby. Later blocks build on those, toward meaning.
One design, stacked many times, each copy with its own weights.
Needs
- The transformer block video
Attention then MLP, each wrapped in normalization and a residual.
Everything this builds on (21 topics, in order)
- Vectors
- Tokens
- Adding and scaling vectors
- Dot product
- Matrices
- Exp and softmax
- Nonlinearity (ReLU)
- Mean, variance, and normalization
- Length, angle, and cosine similarity
- Matrix times vector
- Embeddings
- A neural network layer
- Position information
- Queries, keys, and values
- MLP
- Residual connections
- Attention scores
- Self-attention
- Causal masking
- Multi-head attention
- The transformer block
Leads to
- Next-token prediction and sampling video
Turn the last vector into a score per token, softmax, and pick one.