How can one simple task — predicting the next word — carry us from counting word pairs in Alice in Wonderland to BERT, T5 and GPT? Watch the lecture in nine short chapters with English and Chinese subtitles, follow the lecture map below, then build and sample your own language models in Colab.
Five acts, nine chapters. First why next-word prediction is so powerful, then the narrow sense: count n-grams and generate with them, fix and measure them with smoothing and perplexity. Then the broad sense: learn representations with neural LMs, word vectors, ELMo and BERT, and finally choose an architecture — encoder, encoder-decoder or decoder — and see why decoders took over. Click a chapter to watch it.
A language model scores how likely a text is, or equivalently predicts the next word; a neural LM generates "我思故我在" one token at a time. Because the text is its own label, the task scales, and filling blanks forces the model to learn arithmetic, sentiment, coreference and world knowledge.
A bag of colored shapes, then the Alice passage as a bag of words: sampling, distributions, conditional probability, and the chain rule that turns a sentence probability into a product of next-word predictions.
The Markov assumption keeps only the last n−1 words. Unigram and bigram models for Alice, estimated by relative frequency (MLE), become proper language models once we add EOS, UNK and BOS.
Sampling is spinning a roulette wheel whose slices are the next-word probabilities. The bigram wheel writes "the book her sister was reading"; the trigram wheel has a single slice almost every time and mostly copies the passage.
Large n copies the corpus, and 99.96% of possible Shakespeare bigrams never occur, so MLE gives most sentences probability zero. Smoothing moves mass to unseen events; perplexity (computed in log space) and word error rate tell us which model is better.
N-grams suffer from sparsity and storage. The fixed-window neural LM (Bengio et al., 2003) embeds the context instead of counting it, and its embeddings lead to word vectors and word2vec; subword models handle words the vocabulary has never seen.
ELMo reads with two LSTM language models; BERT uses a bidirectional Transformer trained with masked LM and next sentence prediction, then fine-tunes all weights. A three-step walk-through follows one example from data to inference.
Encoder variants (RoBERTa, SpanBERT, ALBERT, ELECTRA) and encoder-decoders (T5's text-to-text span corruption, BART's denoising), then a side-by-side table of the three families — including the KV cache — and DeepSeek-V4.1-Flash's causal encoder-decoder.
Pretrained decoders as classifiers and as generators, GPT-2's unicorn story, GPT-3's in-context learning and open LLaMA models — ending with the two questions every student should be able to answer.
Three short notebooks turn the lecture into experiments. Click Open in Colab, then Runtime → Run all. Each ends with exercises. All three run on a free CPU runtime; no GPU is needed.
[MASK] with DistilBERT and compare the vectors of "bank"Key terms of the lecture. Each link opens the video at the slide where the idea is explained.
The lecture ends with the architecture trade-offs (slide 143) and a September 2026 release (slide 144). Six things to watch around this lecture's topic:
One simple objective on raw text, one text-in/text-out interface, cheap generation with the KV cache and predictable scaling: the deck's four reasons why almost all large models are decoder-only.
DeepSeek-V4.1-Flash splits 40 layers into a 20-layer causal encoder and a 20-layer decoder that reads one shared KV cache, about a quarter of V4-Flash's KV memory. The name is back; the bidirectional T5 recipe is not.
DeepSeek's Engram adds hashed n-gram embeddings that a Transformer looks up in constant time and gates into its hidden state. V4.1-Flash uses it with n-gram orders 2–4 and 196B Engram parameters next to its 552B backbone.
Diffusion language models write a whole block at once and refine it, a relative of BERT's masked-word prediction. DiffusionGemma, fine-tuned from Gemma 4, denoises 256-token blocks and can still decode autoregressively.
BERT-style models remain the tool for understanding, retrieval and embeddings. ModernBERT brought the encoder up to date: trained on 2 trillion tokens with a native 8,192-token context.
The spin-the-wheel animation was built with Claude Opus 5.5 from the sampling slide, the Alice passage and a short instruction in Chinese — a model that itself writes by sampling the next token, just with a far better distribution.
"You shall know a word by the company it keeps."
Distributional semantics: the idea behind word2vec and every embedding since.
"The fundamental problem of communication is that of reproducing at one point either exactly or approximately a message selected at another point."
Text as a choice among possible messages — the probabilistic view of language. The same paper already generated English from word n-gram approximations, as in Chapter 5.
"But it must be recognized that the notion of ‘probability of a sentence’ is an entirely useless one, under any known interpretation of this term."
Norvig reads it as: a sentence never seen before must get probability zero. Smoothing (slide 66) and neural LMs are the answer.