Semester 2 · Core
Sequence Models & Transformers
https://epochschool.com/subjects/sequence-models-transformers
Text, speech, transactions and sensor streams all arrive as sequences, and modern AI is built on the models that read them.
You start from language modelling with counts and word embeddings, build recurrent networks, LSTMs and encoder-decoders with attention, and then construct the Transformer piece by piece, from scaled dot-product attention and positional encodings to pretraining objectives, tokenisation and decoding. You finish with the engineering of long context and a look at Transformers for images and time series, implementing every model on a CPU and explaining why it works.
- Prerequisites
- Required: Finish this subject before you start. The subject builds directly on it.Corequisite: Take this subject before or alongside, in the same semester. Chapters lean on it as you go.Recommended: Helpful background. You can start without it if you are willing to fill the gaps.
What you’ll be able to do
- LO1Factorise sequence probabilities with the chain rule, build and smooth n-gram language models, and evaluate any language model by cross-entropy, perplexity or bits per byte on held-out data.
- LO2Derive, implement and evaluate word embeddings (PPMI with SVD, skip-gram with negative sampling, GloVe) and explain what static embeddings capture and miss.
- LO3Implement recurrent networks and backpropagation through time from first principles, and analyse vanishing and exploding gradients through Jacobian products.
- LO4Derive, implement and choose between gated recurrent cells (LSTM, GRU) and recurrent architectures (stacked, bidirectional, encoder-decoder) for a given sequence task.
- LO5Derive and implement attention mechanisms (additive, multiplicative, scaled dot-product and multi-head) with padding and causal masks, and explain how attention removes the encoder-decoder bottleneck.
- LO6Build a Transformer from its components (positional encodings including RoPE, pre-LN residual blocks, feed-forward layers), and compute its parameters, FLOPs and memory.
- LO7Compare encoder-only, decoder-only and encoder-decoder models with their pretraining objectives (causal and masked LM), and explain how tokenisation choices affect cost, quality and comparisons.
- LO8Implement and judge decoding strategies (greedy, beam, temperature, top-k, top-p) and KV caching for a given generation task.
- LO9Analyse the cost of attention at long context, explain efficient alternatives (local and linear attention, IO-aware exact attention, grouped-query attention, state-space models), and apply Transformers beyond text with sound baselines.
Chapters
- 01Sequences, probability and language models
- 02Word embeddings: meaning from context
- 03Recurrent neural networks and backpropagation through time
- 04Long-range memory: vanishing gradients, LSTM and GRU
- 05Encoder-decoder models
- 06Attention: learning where to look
- 07Self-attention in depth
- 08The Transformer architecture
- 09Pretraining objectives and tokenisation
- 10Decoding: from probabilities to text
- 11Efficient attention and long context
- 12Transformers beyond text
Graded labs
- L1
Language models and word vectors from counts and from prediction
After chapter 2 · about 9 hours · Railway-announcement corpus · CC BY 4.0 (own work) · Runs on a CPU
- L2
Recurrent networks from scratch: BPTT, vanishing gradients and gated cells
After chapter 4 · about 10 hours · Optical recognition of handwritten digits · BSD-3-Clause (scikit-learn) · Runs on a CPU
- L3
Normalising dates with an attentive encoder-decoder
After chapter 6 · about 10 hours · Synthetic date-normalisation pairs · CC BY 4.0 (own work) · Runs on a CPU
- L4
A small Transformer language model from scratch
After chapter 9 · about 10 hours · Railway-announcement corpus · CC BY 4.0 (own work) · Runs on a CPU
- L5
Decoding, KV caching and efficient attention
After chapter 11 · about 10 hours · Railway-announcement corpus · CC BY 4.0 (own work) · Runs on a CPU
Before you start
Required
Finish this subject before you start. The subject builds directly on it.
Linear Algebra & Calculus for ML
Corequisite
Take this subject before or alongside, in the same semester. Chapters lean on it as you go.
Neural Networks & Deep Learning
Recommended
Helpful background. You can start without it if you are willing to fill the gaps.
Probability & Statistics for ML
Where it leads
NLP & Language Model Foundations
Building and Training LLMs from Scratch
LLM Applications: Retrieval, RAG and Agents
Image Formation and Classical Computer Vision
Deep Visual Recognition
Vision-Language, 3D Vision and World Models
Capstone Project
How it’s taught
You read short sections written for the page. Each ends with a check, and in-browser exercises let you practise. Graded labs run on your own cloud lab machine, CPU-friendly.
No videos. No live classes. No AI tutor.