Phase 5 of 12 · about 14 hours of study
Transformers
Attention, GPT from scratch and pretraining. 21 lessons, about 14 hours of study, in four tracks. One lesson is free to try without an account: the first, Language modeling. The rest need a free account.
Start with Language modeling Create a free account
What you'll learn
Language modeling
- Language modeling FreePredict the next token, and score it with cross-entropy.
- Tokenization and BPEHow tokenizers are built from data.
- A bigram modelThe simplest language model, built from counts.
- Sampling strategiesTemperature, top-k and top-p: turning probabilities into text.
- Neural language modelsWhy counting fails, and what embeddings fix.
Attention
- Attention: the intuitionEach token decides which other tokens matter to it.
- Queries, keys and valuesThe three projections behind attention.
- Scaled dot-product attentionThe attention formula, line by line.
- Causal maskingStop tokens from seeing the future.
- Multi-head attentionSeveral attention patterns in parallel.
The transformer
- Positional encodingsTell the model where each token sits.
- The transformer blockAttention, MLP, residuals and norms together.
- The GPT architectureA stack of decoder blocks that predicts the next token.
- Build a tiny GPTWrite and train a small GPT from scratch.
- Encoders and embedding modelsBERT-style models and where they fit.
Scale & inference
- Pretraining at scaleData, compute and what models learn from the internet.
- Scaling lawsHow loss falls predictably with size, data and compute.
- Inference and the KV cacheWhy generation is fast after the first token.
- Long contextEfficient attention and million-token windows.
- Mixture of expertsRoute each token to a few specialist sub-networks.
- Multimodal transformersHow models see images and hear audio.
Before you start
Lessons here build on earlier phases:
The placement test can mark off what you already know, so you only study what's new to you.
What you'll build
Write and train a small GPT from scratch. Read the tutorial.
- Prepare a corpus for a language model: tokenize, split, and batch with shifted targets
- Train a small GPT from scratch and watch its loss fall
- Generate text from it and judge what it has and hasn't learned
When you finish
Finish every lesson in this phase, or show you know it in the placement test, and you earn a certificate of completion, "Transformers (Phase 5)", with its own link you can share.