Maps to: UC Berkeley CS294-158 Deep Unsupervised Learning (Spring 2024; Pieter Abbeel, Wilson Yan, Kevin Frans, Philipp Wu), Lecture 1 · Thu 1/18/2024 · Intro: Logistics and Motivation. Reading: the Lecture 1 slides (62 slides; PDF and video linked from https://sites.google.com/view/berkeley-cs294-158-sp24/home). The works cited on the slides are listed in §12. Basis: The slides make their case in four steps:
- course logistics;
- a definition of deep unsupervised learning (generative models + self-supervised learning);
- three reasons to care — Hinton’s count of parameters vs data, LeCun’s cake, and “ideal intelligence is compression”;
- a gallery of applications (generation of images, audio, video and text; compression; 3D; science; pretrain-then-adapt) and a summary of where the field stands.
The slides state these arguments in a sentence each and show pictures. These notes add the reasoning behind them (entropy and code length, the chain rule, Kolmogorov complexity, prequential coding, the Bayesian mixture bound, linear probes vs fine-tuning) and five experiments that make each argument measurable. ShapeWorld and every experiment were designed for these notes and do not reflect what was said in class. Code:
code/lecture01/(5 scripts + 5 modules; numpy + PyTorch (CPU) + matplotlib; from 1 second to about 2 minutes each) Reading time: 4–5 hours including running the code
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- State what deep unsupervised learning is, name its two families — generative models (recreate the raw data distribution) and self-supervised learning (solve puzzles hidden in the data itself) — and list what each is used for.
- Reproduce the three arguments for unsupervised learning from the slides and say what each one does and does not prove:
- Hinton’s count of parameters vs data;
- LeCun’s cake (bits per example from rewards, labels and raw data);
- “ideal intelligence is compression”, including what “compressing conditioned on ” means.
- Explain the information content of data in bits: entropy, why a label carries far fewer bits than the example it labels, and why raw pixels are mostly redundant.
- Judge a generative model the two ways this course will: likelihood on held-out data (bits per example) and samples (are they valid, are they new). Recognize memorization, under-fitting and the gap between likelihood and sample quality.
- Explain why a probability model is a compressor: is a code length that an arithmetic coder actually achieves, and the entropy is the floor no lossless method can beat on average.
- Describe how unsupervised pretraining can help, how naive transfer can hurt, and why an ideal learner can only lose a constant number of bits by conditioning on extra data.
- Describe the pretrain-then-adapt protocol (linear probe vs fine-tuning) and read a few-label comparison table critically (baselines, architecture priors).
- Place the course’s model families (autoregressive, flow, latent-variable, implicit, diffusion; self-supervised) on a map with their trade-offs.
0.2 Prerequisites and scope
The original course expects significant experience with probability, optimization and deep learning. This lecture needs much less:
| Assumed | Introduced here | Developed later |
|---|---|---|
| probability distributions, expectations, conditional probability | entropy, code length, KL divergence (intuitive) | maximum likelihood and KL formally (Lecture 2) |
| logarithms (we use base 2: “bits”) | the chain rule for distributions, autoregressive models by counting | neural autoregressive models (Lectures 3–4) |
| a little Python; what “training a neural network” roughly means | arithmetic coding (as a tool) | coding theory: Huffman, Kraft, ANS, bits-back (Lectures 20–21) |
| contrastive “find my twin” learning, linear probes | self-supervised learning in depth (Lectures 13–15) |
If you have never seen entropy before, read §2.2 slowly; everything else builds on it.
0.3 Map
§1 what deep unsupervised learning is: two families, what they are for
§2 argument 1, information: Hinton's count; bits in a label vs bits in an image ← code 01
§3 argument 2, LeCun's cake: what each learning signal can teach ← code 01
§4 what "recreate the data distribution" means; judging models by bits and by samples ← code 02
§5 argument 3, compression: code length = −log2 p; Kolmogorov, Solomonoff, AIXI;
pretraining as conditional compression ← code 03, 04
§6 self-supervised learning: a puzzle without labels, then few labels ← code 05
§7 the gallery: what deep unsupervised learning can do (and where each item is explained)
§8 the map of the course
§9 summary §10 common pitfalls §11 exercises §12 further reading §13 next lecture
Suggested order: §1 → §2 → run 01 → §3 → §4 → run 02 → §5.1–5.4 → run 03 → §5.5–5.7 → run 04 → §6 → run 05 (about 2 minutes) → §7 → §8.
0.4 Notation (used throughout the course)
| Symbol | Meaning |
|---|---|
| one data example: an image, a sentence, a sound clip, flattened into a vector | |
| the dimension of (number of pixels, characters, …) | |
| the data distribution: the unknown process that produced the examples; we only see samples | |
| a model distribution with parameters | |
| the empirical distribution: probability on each training example | |
| logarithm base 2; quantities measured with it are in bits ( gives nats; 1 nat bits) | |
| entropy of a random variable (§2.2) | |
| , | conditional entropy, mutual information (§2.3) |
| Kullback–Leibler divergence (§4.2) | |
| , | Kolmogorov complexity: length of the shortest program printing (given ) (§5.5) |
0.5 About CS294-158
CS294-158 is a PhD-level Berkeley course taught by Pieter Abbeel with Wilson Yan, Kevin Frans and Philipp Wu in Spring 2024. It was first offered in Spring 2019 and again in Spring 2020 (earlier staff included Peter Chen, Jonathan Ho, Aravind Srinivas, Alex Li and Wilson Yan). The 2024 slides call it the third offering and add a fun fact in the summary: the Denoising Diffusion Probabilistic Models paper (Ho, Jain & Abbeel) was written right after the 2020 semester ended — the course’s own staff helped start the diffusion era it now teaches in Lecture 11.
The format:
- 13 weekly sessions of 3 hours (Thursday afternoons), two of them split into two lectures.
- 4 homeworks (60% of the grade), public at https://github.com/rll/deepul : autoregressive models, latent variable models, GANs, diffusion models.
- A midterm (10%). Its format is unusual and worth copying for self-study: the staff publish ~20 questions with answers in advance, and the exam asks a subset. The stated rationale is to make students fully internalize the key derivations.
- A final project (30%): exploring and pushing the boundaries of unsupervised learning, ideally the seed of a conference paper.
These notes turn the 13 sessions into 25 lectures (the long “core model” sessions become 2–3 lectures each); see SYLLABUS.md for the full map and the homework mapping.
0.6 The toy world of this course: ShapeWorld
Real data have no formula. You can train a model on CIFAR-10 and measure 2.8 bits per dimension, but nobody can tell you the true number, whether a sample “could have occurred”, or how many bits the label really removes. So the code of these notes uses a world made by code, whose distribution is known exactly:
left panel (12x12) │ right panel (12x12) one ShapeWorld image = 12 x 24 binary pixels
· · · · · ██· · · · · │· · · · · · · · · · · ·
· · · · ██████· · · · │· · · · · · · · · · · · each panel: one of 8 shapes
· · · ██████████· · · │· · ██████████· · · · · square, frame, disk, ring,
· · ██████████████· · │· ██████████████· · · · triangle, diamond, plus, cross
· ██████████████████· │██████████████████· · · one of 4 sizes (tiny / small / big / huge)
... │... an integer position where it fits
"a huge triangle at the middle center and a big disk at the middle center."
The generating process is a few lines:
- Draw the left shape kind uniformly from 8. With probability the right shape copies it; otherwise the right shape is drawn uniformly too. (This one rule couples the two halves of the image: a long-range dependency that local models cannot see.)
- For each panel independently, draw a size uniformly and a center uniformly among the positions where the shape fits.
- Render the shapes with a deterministic program (
toy_worlds.py); write a caption from the same latents.
Because every latent is discrete, we can enumerate everything: 960 configurations per panel, possible images (all distinct), and an exact for any binary image (zero for images the world cannot produce). The code can therefore report, for any model, exactly how far it is from the truth.

Twelve ShapeWorld images with their captions (01_meet_shapeworld_and_count_bits.py). The red line separates the two panels.
How ShapeWorld differs from real data — keep this in mind whenever a conclusion depends on it:
- It is tiny and clean: 17.8 bits of information per image instead of thousands. Everything is learnable from ~ examples.
- It has no noise and no texture: every pixel is determined by the latents.
- Its symmetries are simple (translation), so a convolutional network’s built-in prior fits it almost perfectly (this matters in §6).
1. What is deep unsupervised learning?
1.1 The definition on the slide
The slides define deep unsupervised learning as capturing rich patterns in raw data with deep networks in a label-free way. Each part of that phrase is doing work:
- Raw data: pixels, audio samples, characters — what sensors and the internet produce in enormous amounts, without anyone annotating it.
- Label-free: no human tells the learner “this is a cat” or “this review is positive”. Whatever the learner learns, it extracts from the data alone.
- Rich patterns: not one number (a class) but the whole structure of the data — that shapes are solid, that rings are hollow, that “huge” is followed by a shape name, that the right shape tends to copy the left one.
- Deep networks: the patterns are captured by neural networks, because high-dimensional data need flexible function classes with shared parameters (§4.5).
Compare with supervised learning, which learns a mapping from pairs where a human (or some process) supplied . Supervised learning only needs to capture the patterns relevant for predicting ; everything else in may be ignored. Unsupervised learning has no such shortcut: it must model itself.
1.2 Two families
The slides split the field into two families, which correspond to the two halves of this course:
| Generative models | Self-supervised learning | |
|---|---|---|
| Slide definition | recreate the raw data distribution | solve puzzle tasks whose solution needs semantic understanding |
| What is learned | a distribution | a representation (a feature vector) |
| What you get | samples, probabilities, compression, conditional generation | features for downstream tasks (classification, detection, control, …) |
| Examples | autoregressive models (GPT), flows, VAEs, GANs, diffusion | predict the masked word (BERT), masked patches (MAE), which views belong together (contrastive learning) |
| Lectures | 2–12, 16–17, 20–21 | 13–15, 18–19 |
The boundary is blurry, and deliberately so. A next-word predictor like GPT is a generative model (it defines by the chain rule) and a self-supervised learner (its “puzzle” is “guess the next word”; its internal activations are excellent features). Generative modeling is the most demanding puzzle of all: to predict every part of the data, you must have captured every pattern.
1.3 What a generative model is for
A model of the data distribution can be used in several ways, and different model families are good at different ones (§8):
- Sampling: draw new examples — new images, voices, sentences, 3D shapes.
- Density evaluation: compute for a given . This enables:
- compression (§5): a likely gets a short code;
- anomaly detection: a very unlikely is suspicious (with caveats we meet later);
- comparing models: the one assigning higher probability to held-out data has captured more of the patterns (§4).
- Conditional generation: — an image given a caption, speech given text, a completion given a prompt, a high-resolution image given a low-resolution one. Almost every “generative AI” product is a conditional generative model.
- Representation learning: the internal variables of the model (latents, activations) as features.
1.4 Why “deep”?
Generative models are old (mixtures of Gaussians, hidden Markov models, n-gram language models). What changed is the dimension and complexity of the data that can be modeled. A color image has about 50,000 dimensions; a model for it needs:
- flexibility (natural images are not a mixture of a few Gaussians),
- parameter sharing (the same edge detector should work everywhere in the image), and
- efficient training on millions of examples (stochastic gradient descent).
Deep networks provide all three. §4 shows, with counting models on ShapeWorld, what happens without them: the best “count table” model stays far above the achievable floor, no matter how much data it sees.
2. Argument 1 — information: more parameters than data
2.1 Hinton’s count
The slides open the motivation with a remark by Geoffrey Hinton (Reddit AMA, 2014). Paraphrased: the brain has about synapses, and we live for only about seconds, so we have far more parameters than data. Hinton’s conclusion: we must be doing a lot of unsupervised learning, because only the perceptual input itself is rich enough — on the order of dimensions of constraint per second.
The arithmetic (computed by script 01, Part 3):
Suppose a teacher gave you a label every second of your life, each one of 1000 classes. A label carries at most bits, so labels would supply about 10 bits per second — about 10,000 times too few to determine parameters per second. Raw perception (millions of photoreceptors, hearing, touch, proprioception) delivers vastly more.
This is a heuristic, not a proof: synapses are not independent free parameters, and learning does not need to “determine” every parameter exactly. But the order-of-magnitude gap is the point: labels are a thin stream; raw data are a firehose.
2.2 Bits: how much information is in something?
To make “a label carries 10 bits” precise, we need the entropy. For a random variable with distribution ,
Three ways to read this formula:
- Surprise. is how surprising the outcome is: a sure event () has surprise 0; a fair coin flip has surprise 1 bit; one of 8 equally likely shapes has surprise 3 bits. Entropy is the average surprise.
- Yes/no questions. For a uniform choice among outcomes, : you need yes/no questions to identify the outcome. For non-uniform distributions, entropy is the average number of questions with the best questioning strategy (up to rounding; Lecture 20).
- Code length. An ideal code spends bits on outcome — short codes for common outcomes, long codes for rare ones — and bits on average. This is the reading that §5 turns into real files.
Two consequences we will use constantly:
- If takes values, , with the maximum for the uniform distribution.
- If is a function of (like a label computed from an image), then : a summary cannot contain more information than what it summarizes.
2.3 ShapeWorld in bits
Script 01 computes the entropy of a ShapeWorld image exactly, by enumerating all 921,600 images. Because each image corresponds to exactly one configuration of latents, the entropy splits into a budget:
| Part of the description | Bits | Why |
|---|---|---|
| left shape kind | 3.0000 | 8 equally likely kinds |
| right shape kind (given the left) | 2.2169 | copy with probability 0.5: cheaper than 3 bits |
| two sizes | 4.0000 | 4 equally likely sizes each |
| two positions (given the sizes) | 8.5850 | averaged over sizes |
| total | 17.8019 | enumeration over all images gives the same 17.8019 |
As a check, the average of over 20,000 samples is 17.7998 bits (the Monte Carlo estimate of the expectation in the entropy formula).
Where does 2.2169 come from? The right shape equals the left one with probability and is each of the 7 others with probability :
The copy rule saves 0.78 bits per image — this is the mutual information between the two shape kinds. In general, for two variables,
“how many bits of you no longer need once you know ”. Here bits.
Now compare four descriptions of the same image (script 01, Part 2):
| Description | Bits it carries | Bits of the image it leaves open |
|---|---|---|
| label (left shape kind) | 3.00 | 14.80 |
| caption (a short sentence) | 11.97 | 5.83 |
| the image itself, | 17.80 | 0.00 |
| raw pixels, stored naively | 288 | — |
Three observations:
- A label is a very lossy summary. It pins down 16.9% of the image’s information. Knowing “the left shape is a ring” leaves its size, its position, and the entire right panel open: bits.
- Raw pixels are mostly redundant. 288 stored bits, of which only 17.80 are information: of the pixels are predictable from the others. Redundancy is pattern. Once you know a shape is a huge disk centered at (5, 6), you can predict all of its pixels. Finding these patterns is exactly what a generative model and a compressor must do (§4, §5).
- Label < caption < image is a ladder of conditioning information. Generating an image from its label is “inventing 14.8 bits”; from a caption, 5.8 bits. The more abstract the condition, the more the generator must invent — a theme of text-to-image models (Lectures 12, 22).
Run it.
python3 01_meet_shapeworld_and_count_bits.py(about 1 second) prints six samples with captions, the bit budget above, and the comparison in §3.
3. Argument 2 — LeCun’s cake
3.1 The cake
The next slide is Yann LeCun’s cake from his NeurIPS 2016 keynote. If intelligence is a cake, then:
- reinforcement learning is the cherry on top — the learner receives a scalar reward: a few bits, and only for some samples;
- supervised learning is the icing — a human label per example: roughly 10 to 10,000 bits per sample;
- unsupervised / self-supervised learning is the cake itself — the machine predicts any part of its input from any other part: millions of bits per sample.
The slide’s annotation: building machines with common sense that generalize needs a tremendous amount of information, and only the cake provides it.
3.2 The numbers
Script 01 (Part 3) puts the cake in a table. For real datasets we cannot compute the entropy of an image, but we have an upper bound: the best published model’s code length. The Sparse Transformer (Child et al., 2019) reports 2.80 bits per dimension on CIFAR-10 () and 3.44 on ImageNet :
| Learning signal | What one example tells | ShapeWorld | CIFAR-10 | ImageNet 64×64 |
|---|---|---|---|---|
| reinforcement learning | success / failure of an episode | ≤ 1 | ≤ 1 | ≤ 1 |
| supervised learning | the class label, | 3.00 | 3.32 | 9.97 |
| unsupervised / generative | the example itself | 17.80 | ≈ 8,602 | ≈ 42,271 |
| ratio image / label | 5.9× | 2,589× | 4,242× |
The ratio grows with the richness of the data: for our toy shapes an image carries six times more bits than its label; for natural images, thousands of times more.
3.3 What the argument does and does not show
The cake counts bits, not useful bits. Much of the information in a natural image — the exact noise pattern, the texture of a carpet — may be irrelevant to any task you care about, and a model that spends its capacity on it may learn nothing useful. Two questions therefore remain open, and the rest of the course answers them empirically:
- Does learning to predict raw data produce representations that help downstream tasks? (§5.6, §6; Lectures 13–15.)
- Which puzzles focus the learner on the useful bits? (Pixel reconstruction vs contrastive objectives vs predicting in representation space; Lectures 13–14.)
4. What does it mean to “recreate the data distribution”?
4.1 The problem
We are given samples drawn from an unknown , and we want a model that
- can evaluate for any , and
- can sample ,
such that . The catch, stated on the Lecture 2 slides: training only ever sees the empirical distribution (the samples), never itself. We want the model to generalize — to give high probability to examples it has never seen, if they could have come from the same process.
4.2 How to judge a model
This course uses two yardsticks, and §4.4 shows why you need both.
(a) Likelihood on held-out data. Measure the average code length on test examples that were not used for training:
Divided by the dimension this is bits per dimension (bits/dim), the standard unit for image models. Lower is better. There is a hard floor:
because the KL divergence is never negative and is zero only when . So the expected test bits of any model = the entropy of the data + how wrong the model is. In ShapeWorld the floor is 17.80 bits, and any model’s excess over it is exactly its KL divergence from the truth (Lecture 2 derives this identity and its role in maximum likelihood).
(b) Samples. Draw samples and ask:
- validity / realism: could this sample have come from ? In ShapeWorld this has an exact answer: . As partial credit we also count panels that are valid shapes and the number of pixel flips to the nearest valid image.
- novelty: is the sample new, or a copy of a training example? A model that only reproduces training data has not learned the distribution.
For real data, validity is judged by humans or by proxies such as FID (Lecture 9); here we have the ground truth.
4.3 Three models you train by counting
Script 02 trains three kinds of model on 10,000 ShapeWorld images. All are trained by counting — no optimization — so what they can and cannot do is purely a matter of their form.
The memorizer (empirical distribution). Remember every training image; . This is a histogram whose bins are whole images. On its own it assigns probability 0 to every unseen image, so we mix in a tiny escape probability to a fallback model:
Independent pixels. Every pixel is a biased coin with probability of being ink, estimated by counting (with one pseudo-count of each value to avoid zeros):
It generalizes trivially — but it cannot express that ink forms shapes.
Context autoregressive models. Any distribution over variables can be written exactly with the chain rule of probability:
This is an autoregressive model: each pixel is predicted from the pixels before it (in raster order: row by row, left to right). The chain rule is exact but does not yet say how to represent each conditional. Our counting version makes two simplifying choices:
- Locality: where the context is a handful of already-generated neighbours (4, 10 or 23 pixels above and to the left). With binary neighbours there are contexts.
- Parameter sharing: the same table is used at every position. An edge looks the same wherever the shape is, so statistics learned at one place transfer to all others.
Training is counting how often the current pixel is ink in each context. This is how the JBIG fax standard compresses black-and-white documents (its template has 10 neighbours). Lectures 3–4 keep the chain rule and parameter sharing but replace the count table by neural networks (MADE, PixelCNN, Transformers) that can use all previous pixels.
Note one asymmetry, central to autoregressive models. Evaluating is parallel: all conditionals can be computed at once because the true previous pixels are known (the code calls this cond_probs). Sampling is sequential: pixel needs pixels , which exist only after they have been sampled (sample loops over all 288 pixels).
4.4 Results
Script 02, Part 1 (10,000 training images, 2,000 test images, 2,000 samples per model):
| Model | Train bits | Test bits | Bits/pixel | Valid | Panels ok | Flips | Novel valid |
|---|---|---|---|---|---|---|---|
| memorizer () | 13.1 | 191.1 | 0.663 | 100.0% | 100.0% | 0.0 | 0.0% |
| independent pixels | 214.3 | 212.1 | 0.736 | 0.0% | 0.0% | 61.1 | 0.0% |
| context AR, 4 neighbours | 101.1 | 101.9 | 0.354 | 0.0% | 0.0% | 30.3 | 0.0% |
| context AR, 10 neighbours (JBIG) | 68.3 | 68.7 | 0.238 | 0.0% | 0.0% | 33.9 | 0.0% |
| context AR, 23 neighbours | 46.7 | 47.4 | 0.165 | 0.0% | 0.6% | 62.1 | 0.0% |
| true distribution | 17.8 | 17.8 | 0.062 | 100.0% | 100.0% | 0.0 | 87.0% |

Six samples from each model (02_what_does_a_generative_model_learn.py).
Read the table row by row:
- The memorizer needs about 13 bits for a training image — essentially “which of my 9,242 distinct images is it?” () — but 191 bits for a test image, because 87% of the test images are not in the training set and must go through the escape. Its samples are 100% valid and 0% new. It has learned the training set, not the distribution.
- Independent pixels have train ≈ test: no over-fitting at all. But 212 bits per image is only 1.4 times better than storing the raw 288 bits, and the samples are speckle. Generalizing is easy if you learn little.
- Context models drop to 101, 69 and 47 bits as the context grows, still with train ≈ test, thanks to parameter sharing. Yet none of their samples is a valid image: ragged blobs, wandering strokes, staircase edges. They get local statistics right (edges continue, ink comes in runs) but cannot coordinate a whole shape or the copy rule between panels.
- Only the true distribution reaches 17.8 bits and produces samples that are valid and new (87% of them are not in the training set).
The goal of every generative model in this course is the bottom row: low test bits, valid samples, novel samples. The gap between 47.4 bits (the best count model) and 17.8 bits is the room deep generative models must fill; Lectures 3–4 will train neural autoregressive models on the same data and compare against this table.
Likelihood and sample quality are different yardsticks. The 23-neighbour model has the best likelihood of the count models, but its samples are the farthest from valid (62 flips vs 30 for 4 neighbours). The 4-neighbour model mostly leaves the canvas empty, and an almost empty canvas is only a few flips from a tiny shape; the 23-neighbour model scribbles strokes everywhere. A model can be better at assigning probability to real data and worse at producing data — a phenomenon that will matter when we compare likelihood models with GANs (Lecture 9).
4.5 How much context can the data afford?
Script 02, Part 2 varies the amount of training data. Each cell is test bits (train bits in brackets):
| train | ctx 4 | ctx 10 | ctx 18 | ctx 23 | memorizer | test seen | best ctx |
|---|---|---|---|---|---|---|---|
| 30 | 102.5 (114.4) | 74.9 (71.2) | 73.8 (65.0) | 80.7 (65.1) | 226.8 | 0.1% | 18 |
| 100 | 101.5 (100.1) | 71.5 (67.8) | 63.2 (55.5) | 64.3 (52.8) | 223.3 | 0.0% | 18 |
| 1,000 | 101.5 (101.1) | 69.3 (68.6) | 55.5 (54.6) | 51.4 (48.9) | 217.6 | 1.6% | 23 |
| 10,000 | 101.5 (101.3) | 69.1 (68.0) | 53.8 (53.1) | 47.5 (46.7) | 189.5 | 13.1% | 23 |
| 100,000 | 101.4 (101.2) | 69.0 (68.1) | 53.4 (53.0) | 46.4 (46.2) | 122.8 | 43.0% | 23 |
- With 30 images, the 23-neighbour table (8.4 million entries!) over-fits: 65.1 bits on training images but 80.7 on test images, worse than the 18-neighbour model. From 1,000 images on, more context always wins. The best model size grows with the amount of data — the bias–variance trade-off in its simplest form, and the seed of the scaling laws of Lecture 16.
- The memorizer improves only because the test set starts to overlap the training set: big shapes have few positions, so with 100,000 training images 43% of test images have been seen. It still knows nothing about the other 57%.
- Even with 100,000 images the best count model is stuck near 46 bits. More data cannot fix a model family that cannot express global structure. That is why we need deep models: conditionals that look at all previous pixels, with enough parameter sharing to learn from finite data. (The 8.4-million-entry table also shows why “just use a bigger context” fails: a table indexed by binary pixels has entries, which explodes long before . Lecture 2 calls this the curse of dimensionality.)
Run it.
python3 02_what_does_a_generative_model_learn.py(about 6 seconds) prints both tables and three ASCII samples per model.
5. Argument 3 — “ideal intelligence is compression”
5.1 The slide
The third argument on the slides is the most ambitious:
- Ideal intelligence is all about compression — finding all patterns.
- Finding all patterns = a short description of the raw data (low Kolmogorov complexity).
- The shortest code length gives optimal inference (Solomonoff induction), and this extends to optimal acting agents (AIXI).
- If we pretrain on and fine-tune on , and and are related, then compressing conditioned on should be more efficient than compressing outright. Hence pretraining on should aid faster learning of .
To understand it, we first make the bridge between probability and compression completely concrete (§5.2–5.4), then climb to Kolmogorov complexity (§5.5) and finally test the pretraining claim (§5.6).
5.2 A probability model is a compressor
Claim: with a model , any message can be stored in about bits, losslessly. The device that achieves this is arithmetic coding:
start with the interval [0, 1)
for each symbol x_i (here: each pixel, in raster order):
split the current interval into pieces proportional to p(x_i = 0 | x_<i) and p(x_i = 1 | x_<i)
keep the piece of the symbol that actually occurred
after the last symbol the interval has width p(x_1) p(x_2 | x_1) ... = p(x) (the chain rule!)
write down the shortest binary fraction inside it: about −log2 p(x) + 2 bits
A predictable pixel () barely shrinks the interval and costs almost nothing; a surprising pixel shrinks it a lot. The decoder runs the same model, sees the same splits, and recovers the symbols one by one. coding.py implements the classic integer version (Witten, Neal & Cleary, 1987); Lecture 20 proves why it works and why nothing can beat the entropy on average (Kraft’s inequality, Shannon’s theorem).
Two consequences are worth stating now:
- The negative log-likelihood of a model is a file size. The “test bits” of §4 are literally the size of the compressed test set.
- The entropy is the compression floor. No lossless code can beat on average; the true distribution itself achieves it. Better compression ⇔ a better model of the data ⇔ more patterns found. This is the precise sense of “finding all patterns = short description”.
5.3 Compressing ShapeWorld for real
Script 03 compresses 500 test images with each model of §4 and with the true distribution, decompresses them, and compares with three general-purpose compressors at maximum effort, applied to the packed pixel bits:
| Method | (exact) | Ideal (rounded ) | Actual bits/img | Overhead (whole file) | Round trip |
|---|---|---|---|---|---|
| raw pixels | — | — | 288.0 | — | — |
| zlib -9 | — | — | 119.3 | — | yes |
| bz2 -9 | — | — | 124.5 | — | yes |
| lzma (xz) | — | — | 111.7 | — | yes |
| independent pixels | 210.46 | 210.46 | 210.46 | 0.6 bits | yes |
| context AR, 10 neighbours | 69.17 | 69.17 | 69.17 | 0.3 bits | yes |
| context AR, 23 neighbours | 47.31 | 47.31 | 47.31 | 0.9 bits | yes |
| memorizer + escape | 185.48 | 150.56 | 150.57 | 1.6 bits | yes |
| true distribution (whole panels as symbols) | 17.76 | 17.76 | 17.76 | 0.4 bits | yes |

Actual compressed size per image (03_compression_is_likelihood.py). Green dashed line: the entropy, 17.80 bits.
What the table shows:
- Files are as long as Shannon says. For every model, the real file of 500 images is at most ~2 bits longer than the sum of under the probabilities the coder used (the end-of-stream flush). The negative log-likelihood is not an abstract score.
- The ranking of compressors is the ranking of likelihoods, and the true distribution compresses to 17.76 bits per image on these 500 images (the entropy is 17.80; a finite sample can land slightly on either side).
- General-purpose compressors know nothing about shapes. zlib, bz2 and lzma look for repeated byte strings and land at 112–125 bits. A good model beats them by a wide margin (the slides make the same point for learned image coders vs JPEG); a bad one does not — independent pixels lose to lzma.
- A subtle one: the memorizer. The coder must round probabilities to integers (here multiples of ), so no pixel can cost more than 16 bits. For the count models this changes nothing visible. For the memorizer it changes 185 bits into 151: at the first pixel where a new test image departs from every training image, the exact mixture gives that pixel a probability far below (the escape route has to “explain” the whole prefix with the fallback model), and rounding caps the damage. The coder therefore implements a different, better-smoothed model than the one we wrote down. Lesson: the file size measures the model you actually run, including every engineering detail.
The same holds for text. Script 03, Part 2 compresses 1,000 captions (72,471 characters):
| Method | Bits/char | Bytes |
|---|---|---|
| raw text (8-bit characters) | 8.000 | 72,471 |
| zlib -9 | 0.495 | 4,482 |
| bz2 -9 | 0.274 | 2,482 |
| lzma (xz) | 0.498 | 4,508 |
| character 5-gram, trained on 20,000 other captions | 0.232 | 2,104 |
| character 5-gram, adaptive (starts empty, learns while coding) | 0.248 | 2,248 |
The pretrained model wins (bz2’s block-sorting transform suits this repetitive text well and comes within 15%). The adaptive coder is interesting: it starts knowing nothing, predicts each character, pays for it, then learns from it; the decoder does exactly the same with what it has decoded, so the model never needs to be transmitted. Its early ignorance costs only ~7% here because 72,000 characters are plenty for so small a language. Hold on to this idea — “predict, pay, then learn” — it is how we will measure pretraining in §5.6.
Run it.
python3 03_compression_is_likelihood.py(about 20 seconds; most of it is Python looping over 144,000 pixels per model).
5.4 Why compression requires patterns
A counting argument shows why only patterned data can be compressed. There are binary strings of 288 bits but only strings that are shorter. So no lossless compressor can shorten every input; it can only shorten some inputs at the expense of others. A compressor is a bet on which inputs are likely — that is, a probability model. ShapeWorld images compress from 288 to ~18 bits because only of the possible pixel patterns ever occur, and the true model knows which.
(The slides’ “Pied Piper” jokes in Lecture 11 are about exactly this impossibility of universal compression.)
5.5 Kolmogorov complexity, Solomonoff induction, AIXI
Entropy is a property of a distribution. Kolmogorov complexity is the analogous notion for a single object:
on a fixed universal computer (a programming language). Some intuitions:
- A string of a million zeros has tiny : “print ‘0’ a million times” is short. A million fair coin flips have : typically no program is shorter than the string itself.
- For a ShapeWorld image, a program is “render(shape=ring, size=5, x=6, y=5, …)” plus the renderer: the renderer is a fixed cost, and the arguments cost about 18 bits. Kolmogorov complexity is “entropy without a distribution” — it measures how much pattern an individual object has.
- The choice of programming language changes by at most a constant (the length of an interpreter from one language to another) — the invariance theorem.
- is uncomputable: no algorithm can compute it for every . (If one could, the program “print the first string with ” would have length far below yet print a string of complexity above — a contradiction known as Berry’s paradox.) So is an ideal, not a tool. Every real compressor, and every model in this course, gives an upper bound on it.
Solomonoff induction turns this into a theory of prediction. Put a prior on all programs, giving a program of length weight ; predict the continuation of a sequence by weighting every program that is consistent with the observations so far. Short programs (simple explanations) dominate — a formal Occam’s razor. Solomonoff proved that this predictor’s total prediction error on any computable source is bounded by a constant related to that source’s complexity: it learns any computable pattern with a finite number of mistakes. It is uncomputable, but it is the reference point for “optimal inference”.
AIXI (Hutter, 2000) combines Solomonoff prediction with planning: an agent that predicts its environment with the Solomonoff mixture and picks the actions with the highest expected reward. It is the formal model of an “optimally acting agent” mentioned on the slide, and equally uncomputable.
Why bring uncomputable ideals into a practical course? Because they explain why compression is a sensible training objective: a model that compresses data well has found its patterns; the best possible predictor is the best possible compressor; and the Hutter Prize (Lecture 20) even offers money for compressing Wikipedia as a proxy for intelligence. Large language models trained to minimize next-token log-loss are, literally, compressors.
5.6 Pretraining as conditional compression
The slide’s claim uses the conditional complexity : the shortest program that prints when given for free. Two facts about it:
- Conditioning can never hurt (much): . A program for that is given can simply ignore it.
- The savings are the shared information: is (up to logarithmic terms) the algorithmic mutual information between and — large if they share patterns, near zero if they are unrelated.
“Pretraining helps” then means: if and share patterns, a learner who has digested needs fewer bits — fewer examples — to pin down .
To test this we need a computable stand-in for . We use the prequential code length (Dawid’s “predictive sequential” principle, the adaptive coder of §5.3): stream the examples of one by one; for each, predict it, pay bits, then learn from it:
“Start = empty model” is compressing outright; “start = the model pretrained on ” is compressing conditioned on . A learner that learns faster pays fewer bits, so measures learning speed and compression at once.
Script 04 sets up three text corpora:
- (target, scarce): captions in a terse list register,
left: cross, huge, middle center; right: cross, small, top center., from a world where the right shape copies the left one 90% of the time; - (related, plentiful): 20,000 captions in the plain register,
a tiny plus at the middle right and a small plus at the middle center.; - (unrelated): 20,000 lines of arithmetic,
13+22=35.
The model is a character 5-gram (each character predicted from the previous four, Witten–Bell smoothing). We stream 1,000 lines of .
Step 1 — naive pretraining. Start from all of ‘s counts and continue learning on (bits per character over the first lines):
| Starting point | First 10 lines | First 100 lines | First 1,000 lines |
|---|---|---|---|
| scratch (compress outright) | 1.094 | 0.387 | 0.259 |
| pretrained on (related) | 2.767 | 1.378 | 0.856 |
| pretrained on (unrelated) | 2.571 | 0.660 | 0.358 |
| pretrained on 20k lines of itself (ceiling) | 0.210 | 0.238 | 0.242 |
Plan vs reality: naive pretraining on the related corpus makes more expensive at every stage — negative transfer. Twenty thousand plain captions make the model extremely sure that left is followed by and a ... or .; writes left: .... Each surprise costs many bits, and thousands of lines are needed to out-vote 20,000 lines of confident counts. Related is not the same as identical.
Step 2 — how much should the learner trust ? Multiply ‘s counts by a weight ( makes 20,000 lines count like 2):
| : first 10 | : first 100 | : first 1,000 | : first 10 | : first 100 | : first 1,000 | |
|---|---|---|---|---|---|---|
| 0 (scratch) | 1.094 | 0.387 | 0.259 | 1.094 | 0.387 | 0.259 |
| 0.0001 | 0.663 | 0.329 | 0.254 | 1.132 | 0.392 | 0.260 |
| 0.001 | 0.946 | 0.394 | 0.265 | 1.319 | 0.418 | 0.263 |
| 0.01 | 1.502 | 0.612 | 0.327 | 1.688 | 0.480 | 0.276 |
| 0.1 | 2.130 | 0.970 | 0.523 | 2.125 | 0.567 | 0.309 |
| 1 | 2.767 | 1.378 | 0.856 | 2.571 | 0.660 | 0.358 |
Used as a weak prior, helps exactly where the slides say: at the start, when data are scarce (the first 10 lines cost 0.663 instead of 1.094 bits per character). Unrelated arithmetic never helps at any trust level.
Step 3 — an ideal conditional compressor. The right trust depends on how related the corpora are, which we do not know in advance. The principled answer is to not choose: run all trust levels (“experts”) in parallel and predict with their Bayesian mixture
where the weights are the posterior probability of each expert given everything seen so far. The mixture’s probability of the whole stream is for every , so
With trust levels (including , i.e. ignoring ), the mixture is never more than bits worse than the best expert in hindsight. Script 04, Part 3:
| Pretraining corpus | scratch | best expert | mixture | Mixture − best | Final weights ( = 0, 1e-4, 1e-3, 1e-2, 0.1, 1) |
|---|---|---|---|---|---|
| 17,757 | 17,395 () | 17,398 | +2.6 | 0.00 1.00 0.00 0.00 0.00 0.00 | |
| 17,757 | 17,757 () | 17,760 | +2.6 | 1.00 0.00 0.00 0.00 0.00 0.00 |
This is in miniature: an ideal learner can never lose more than a constant number of bits by conditioning on extra data — it can always fall back on ignoring it — and it gains when the data share patterns. A non-ideal learner (naive fine-tuning) can be hurt, which is why transfer learning is an empirical science and why practitioners tune learning rates, freeze layers, or mix pretraining data into fine-tuning.
Step 4 — learning speed. Held-out bits per character after seeing lines of :
| Starting point | =0 | 3 | 10 | 30 | 100 | 300 | 1,000 |
|---|---|---|---|---|---|---|---|
| scratch | 5.459 | 1.295 | 0.840 | 0.317 | 0.252 | 0.248 | 0.246 |
| , (naive) | 9.177 | 2.791 | 1.985 | 1.306 | 1.061 | 0.876 | 0.682 |
| , | 2.508 | 0.786 | 0.513 | 0.313 | 0.255 | 0.249 | 0.246 |
| mixture over , | 2.052 | 0.786 | 0.513 | 0.313 | 0.255 | 0.249 | 0.246 |
| mixture over , | 7.421 | 1.295 | 0.840 | 0.317 | 0.252 | 0.248 | 0.246 |
| ceiling: pretrained on | 0.244 | 0.244 | 0.244 | 0.244 | 0.244 | 0.244 | 0.244 |

Left: learning curves on held-out lines. Right: total code length of the stream as a function of the trust (solid) and for the Bayesian mixture (dashed) (04_pretraining_as_conditional_compression.py).
How much is worth? The mixture after 3 lines of predicts as well as the scratch model after about 11 lines; after 10 lines, as well as scratch after about 20. The benefit is concentrated at the beginning: by 100 lines every sensible starting point has converged to ~0.25 bits per character. Pretraining buys faster learning of , not a better final model — exactly what the slide claims (pretraining aids faster learning). In modern practice the target data are often so scarce (a few examples in a prompt, a few hundred labeled images) that “faster learning” is everything.
Run it.
python3 04_pretraining_as_conditional_compression.py(about 25 seconds).
5.7 What the compression argument does and does not say
- It does say that predicting raw data well is the same as compressing it, that compression requires finding patterns, and that an ideal learner can only benefit from related extra data.
- It does not say that the patterns found are the ones a downstream task needs (the cake caveat of §3.3), nor that a particular learning procedure will transfer well (Step 1 above).
- The useful takeaway for practice: log-likelihood (bits) is a universal, task-free yardstick for how much a model has learned about data. Lecture 16 shows that this yardstick improves smoothly and predictably with scale.
6. Self-supervised learning: a puzzle without labels
6.1 The idea
The second family on the slides learns from puzzle tasks whose solution needs semantic understanding. A puzzle is a prediction task whose answer is hidden in the data itself, so no human labels are needed:
- predict the next word (GPT) or a masked word (BERT);
- predict masked image patches (MAE);
- predict the color of a grayscale image, or the relative position of two patches;
- tell which of many images is another view of the same scene (contrastive learning: CPC, SimCLR, MoCo).
The bet is that solving the puzzle forces the network to represent what matters. To fill in a masked word you must understand the sentence; to recognize two crops of the same photo among thousands you must encode what is in the photo, not where the crop was taken. After pretraining, the network’s internal representation is reused for a downstream task with few labels.
6.2 Our puzzle: “find my twin”
Script 05 uses single 12×12 ShapeWorld panels; the downstream task is to classify the shape kind (8 classes). The puzzle uses 20,000 unlabeled panels:
- Take a batch of 256 images. Make two random views of each: shift it by up to ±2 pixels and flip 3% of its pixels.
- A small CNN maps every view to a vector. For each view in the first set, the network must pick its twin (the view of the same image) among the 256 views of the second set.
- The loss is a 256-way cross-entropy over cosine similarities — the InfoNCE loss of contrastive learning (Lecture 14):
The augmentations define what the representation should ignore (small shifts, pixel noise); whatever survives them (which shape, roughly how big) is what the network can use to find the twin.
Training (600 steps of 256 images):
| Step | InfoNCE loss | Puzzle accuracy |
|---|---|---|
| 1 | 5.545 | 5.5% |
| 120 | 3.902 | 8.8% |
| 240 | 3.138 | 16.1% |
| 360 | 2.880 | 18.7% |
| 480 | 2.759 | 19.3% |
| 600 | 2.686 | 20.4% |
(Chance is 1/256 = 0.4%, i.e. a loss of .) The accuracy stays modest because the puzzle is partly unsolvable: two images of the same shape and size one pixel apart look identical after random shifts, so the network cannot know which of them is the twin. Solving the puzzle perfectly is not the goal; the features are.
6.3 How to evaluate a representation
Two standard protocols:
- Linear probe. Freeze the network, compute features for the labeled examples, and train only a linear classifier on top. This measures how ready to use the features are: a linear classifier can only exploit what the representation makes explicit.
- Fine-tuning. Start from the pretrained network and train all weights on the labeled examples (“pretrain, then adapt”). This measures how good the pretrained weights are as an initialization.
We compare representations at 1, 3, 10 and 100 labeled examples per class, averaging over 3 random draws of the labeled examples, with two controls:
- a random CNN (same architecture, random weights), which separates what the architecture gives for free (convolutions and pooling already ignore position to a degree) from what the puzzle learned;
- a supervised CNN from scratch (same architecture and augmentations, trained end-to-end on the labels only), which shows what the labels alone achieve.
6.4 Results
Test accuracy (mean ± std over 3 draws; chance 12.5%). The first four rows are linear probes on frozen features; the last two train the whole network:
| Representation | 1 / class | 3 / class | 10 / class | 100 / class |
|---|---|---|---|---|
| raw pixels (144-d) | 22.0% ± 5.2% | 31.5% ± 1.7% | 43.9% ± 0.5% | 62.3% ± 0.4% |
| PCA-32 of the unlabeled pool | 20.4% ± 1.3% | 26.9% ± 1.5% | 42.5% ± 0.4% | 57.0% ± 0.4% |
| random CNN (64-d) | 27.0% ± 2.3% | 41.8% ± 2.1% | 64.2% ± 2.9% | 85.6% ± 0.5% |
| SSL CNN, twin puzzle (64-d) | 65.6% ± 2.7% | 76.5% ± 2.6% | 94.6% ± 1.0% | 99.0% ± 0.1% |
| supervised CNN from scratch (end-to-end) | 46.0% ± 6.2% | 78.9% ± 4.3% | 97.4% ± 0.4% | 97.8% ± 1.5% |
| SSL CNN, then fine-tuned (end-to-end) | 55.4% ± 3.5% | 82.2% ± 2.8% | 98.5% ± 0.8% | 99.8% ± 0.3% |

Few-label shape classification with different representations (05_self_supervised_puzzle.py).
What the table says:
- With one label per class, frozen puzzle features are the best method in the table: 65.6%, against 22–27% for raw pixels, PCA and the random CNN, and 46% for the same CNN trained end-to-end on the 8 labeled images. The invariance to position was learned from unlabeled data; the labels only had to name the clusters.
- Fine-tuning the pretrained network beats training it from scratch at every label budget (55 vs 46, 82 vs 79, 98.5 vs 97.4, 99.8 vs 97.8). This is “pretrain, then adapt” in its most common form.
- With a single label per class, fine-tuning loses to the frozen probe (55% vs 66%): 8 examples are too few to update a whole network without damaging what it learned. This is why tiny label budgets are usually handled with frozen features, linear probes, or light-touch adaptation (and, for language models, with prompting instead of training).
- Part of the gain is the architecture. The random CNN beats raw pixels clearly (64% vs 44% at 10 labels per class) — convolutions and pooling are a strong prior for “a shape is a shape wherever it is”. The puzzle then adds the rest (64% → 95%).
- Plan vs reality: the supervised baseline is strong here. With 10 labels per class, the CNN trained from scratch reaches 97%: in this toy world a CNN with shift augmentation already encodes most of what the task needs. Our first version of the baseline was under-trained (300 full-batch steps; ~65% even at 100 labels per class) and made self-supervision look far better than it is. Always tune baselines before concluding that a new method helps. The gaps shrink as labels grow: unsupervised pretraining matters most when labels are scarce.
The slides’ summary makes the historical version of point 5: until 2019, self-supervised pretraining was far worse than supervised pretraining for vision tasks like detection; then contrastive methods (MoCo, SimCLR) and later masked autoencoders (MAE, November 2021) overtook it. What holds today may not hold a year from now.
Run it.
python3 05_self_supervised_puzzle.py(about 2 minutes;--quickgives a 25-second smoke test with fewer steps and repeats, and different numbers).
7. The gallery: what deep unsupervised learning can do
The second half of the slides is a gallery. Here it is as a table, with where each item is explained in this course.
7.1 Generating data
| Domain | Examples on the slides | Lectures |
|---|---|---|
| Images (unconditional / class-conditional) | Deep Belief Nets (Hinton, Osindero & Teh, 2006); VAE (Kingma & Welling, 2013); GAN (Goodfellow et al., 2014); DCGAN (Radford, Metz & Chintala, 2015); super-resolution (Ledig, Theis, Huszár et al., 2017); CycleGAN (Zhu, Park, Isola & Efros, 2017); BigGAN (Brock, Donahue & Simonyan, 2018); StyleGAN (Karras, Laine & Aila, 2018); DDPM (Ho, Jain & Abbeel, 2020) | 7–12, 19 |
| Text to image | prompts rendered by modern text-to-image systems (“a photo of a Shiba Inu dog with a backpack riding a bike …”) | 12, 22 |
| Audio and speech | WaveNet (van den Oord et al.); Tacotron 2 (Shen et al., 2018); AudioCraft (Copet et al., 2023); commercial text-to-speech; voice conversion | 3–4 |
| Video | DVD-GAN (Clark, Donahue & Simonyan, 2019); Emu Video (Girdhar et al., 2023); VideoPoet (Kondratyuk et al., 2023); UniSim — video generation as an interactive simulator for control (Yang et al., 2023) | 17 |
| Text | char-rnn generating Shakespeare-like text and LaTeX “math” (Karpathy, 2015); GPT-2 continuing a human-written prompt (Radford et al., 2019); ChatGPT producing JSON and long summaries (2023) | 4, 16 |
| 3D | GRAF (Schwarz et al., 2020); GET3D (Gao et al., 2022) | 12, 25 |
| Science | AlphaFold’s structure prediction (Jumper et al., 2021) as an example of deep learning for science | 24 |
The image timeline is worth staring at: from blurry digits in 2006 to photorealistic, controllable images in a little over a decade, through four different model families. The 2020 DDPM row is where the 2020 offering of this course ended — and the start of the diffusion era.
7.2 Compression
Two slides: lossless compression, where learned generative models give better bit rates than distribution-unaware methods (our §5.3 in miniature), and lossy compression, where learned codecs beat hand-designed ones like JPEG at the same visual quality. Lectures 20–21 cover lossless coding with AR models, VAEs (bits-back) and flows.
7.3 Pretrain, then adapt
The rest of the gallery is about using unsupervised learning as a pretraining step:
- Foundation models (Bommasani et al., 2021): one model pretrained on broad data, adapted to many tasks.
- The sentiment neuron (Radford, Józefowicz & Sutskever, 2017): a character-level language model trained only to predict the next character of product reviews developed a single unit that tracks sentiment — a downstream concept emerging from a generative objective.
- BERT and the GLUE leaderboard: masked-language-model pretraining transformed NLP benchmarks; the slides note production-level impact (Google Search powered by BERT).
- Few-shot and prompting (Llama 2; zero-shot chain-of-thought, Kojima et al.): pretrained language models solve tasks from a handful of examples, or from an instruction alone.
- Vision: a slide recalls a famous bet — Jitendra Malik promised Alyosha Efros a gelato if, by autumn 2015, a method without extra human annotations matched R-CNN on PASCAL VOC detection — next to the data-efficiency results of CPC (Hénaff, Srinivas et al.) and the masked autoencoders of He et al. (2021).
- Unsupervised learning scales with data: the more unlabeled data, the better the representations — the empirical backbone of the whole “pretrain, then adapt” paradigm.
Lectures 13–16 and 18 explain these methods; §5.6 and §6 above are their toy versions.
7.4 The summary slide
The slides close with four statements worth remembering:
- Unsupervised learning is advancing rapidly thanks to compute, deep-learning engineering practices, datasets, and many people working on it.
- It is not just of academic interest: language modeling, image generation, and vision / language / multimodal pretraining all work really well and have production-level impact.
- What holds today may not hold even a year from now. Examples: self-supervised pretraining was much worse than supervised pretraining for detection and segmentation until 2019 and is now better; masked image modeling did not work for representation learning until MAE (November 2021).
- Autoregressive models, flows, VAEs, GANs and diffusion models still have room for surprising capabilities, especially in newer domains (multimodal, video, robotics, biology, the sciences), and the core of unsupervised learning may still see major innovations — as the diffusion paper written right after the 2020 offering illustrates.
8. The map of the course
The course answers one question — how do we represent and learn a distribution over high-dimensional data? — five ways, then uses the answers:
| Family | Idea in one line | Exact ? | Fast sampling? | Latent representation? | Lectures |
|---|---|---|---|---|---|
| Autoregressive | chain rule; each conditional a neural network | yes | no | no | 2–4 |
| Flows | invertible network to a simple distribution | yes | yes* | yes | 5–6 |
| Latent variable (VAE) | , variational bound | bound | yes | yes | 7–8 |
| Implicit (GAN) | sampler trained against a discriminator | no | yes | yes* | 9–10 |
| Diffusion | learn to reverse gradual noising | bound | no* | partly | 11–12 |
| Self-supervised | puzzles on unlabeled data | — | — | the point | 13–15 |
(*: with caveats discussed in the lectures — e.g. flows need a cheap inverse; GANs have no encoder unless one is added (BiGAN); diffusion sampling can be distilled to a few steps.)
Then: large language models (16), video (17), semi-supervised learning and unsupervised alignment (18–19), compression (20–21), multimodal models (22), parallel training (23), and two guest frontiers — science (24) and neural radiance fields (25). Each original homework (autoregressive models, latent variables, GANs, diffusion) appears as a CPU-sized experiment in the matching lecture; see SYLLABUS.md.
A thread to follow through the whole course: the three yardsticks of §4 and §6 — bits on held-out data, validity and novelty of samples, usefulness of representations. Every model family will be measured on ShapeWorld with them, against the exact floor of 17.80 bits.
9. Summary
- Deep unsupervised learning captures patterns in raw data with deep networks, without labels. Its two families are generative models (learn : sample, evaluate, compress, generate conditionally) and self-supervised learning (solve puzzles hidden in the data; keep the representation).
- Information argument: labels carry few bits (3 bits in ShapeWorld, ~10 for ImageNet), raw data many (17.8 bits in ShapeWorld, thousands for natural images). Raw pixels are mostly redundant (93.8% in ShapeWorld): redundancy is pattern.
- Judging a generative model: expected test bits , so the entropy is a floor; samples must be valid and novel. The memorizer is perfect on training data and useless on new data; independent pixels generalize but learn nothing; local autoregressive models capture local structure but not global shape. Likelihood and sample quality can disagree.
- Compression: a model compresses to bits (arithmetic coding makes it real), so negative log-likelihood is a file size and the entropy is the compression floor. Kolmogorov complexity, Solomonoff induction and AIXI are the uncomputable ideals behind “intelligence = compression”.
- Pretraining as conditional compression: — an ideal learner (a Bayesian mixture over how much to trust ) never loses more than a constant and gains when the data share patterns; naive transfer can hurt. The benefit is faster learning when target data are scarce.
- Self-supervised pretraining (a “find my twin” puzzle) gives features that classify shapes from one label per class far better than raw pixels; fine-tuning beats training from scratch at every label budget — but strong, well-tuned baselines and architectural priors explain part of the story.
10. Common pitfalls
- “Lower training loss = better generative model.” The memorizer has the lowest training bits of all (13.1) and the worst test bits but one. Always measure on held-out data.
- Comparing bits across datasets or dimensions. Bits per image depend on image size and content; bits/dim normalizes size but not difficulty. 0.062 bits/pixel on ShapeWorld and 2.80 bits/dim on CIFAR-10 say nothing about which model is better.
- Treating likelihood as sample quality. The 23-neighbour model beats the 4-neighbour model by 54 bits per image yet its samples are farther from valid images (§4.4). Both yardsticks are needed.
- Forgetting that a model must assign probability to everything that can occur. A single zero probability on a test example means infinite bits. Smoothing, escapes and rounding floors are modeling decisions, and they show up in the numbers (§5.3).
- Reading the compression argument as a guarantee for real training procedures. holds for an ideal learner; naive fine-tuning on a related but different corpus made things worse (§5.6).
- Under-tuned baselines. A weak baseline can make any new method look good (§6.4, point 5).
- Confusing “bits in the data” with “useful bits”. The cake counts information, not relevance (§3.3).
- Assuming the toy world transfers literally. ShapeWorld has 17.8 bits per image, no noise and a translation symmetry that CNNs encode for free. Use it to understand mechanisms, not to predict the size of effects on real data.
11. Exercises
Exercise 1 (bits, by hand). Compute the entropy of a single ShapeWorld panel (8 shapes, 4 sizes, uniform positions where the shape fits in a 12×12 panel). Compare with ShapeWorld(n_panels=1).exact_stats().
Answer
bits. The code prints H_X: 9.2925. (Positions given the size are uniform, so their entropy is of their number, averaged over the sizes.)
Exercise 2 (the copy knob). How does the entropy of a two-panel image change if (always copy) or (independent shapes)? What is the mutual information between the two shape kinds in each case?
Answer
Only the right-shape term changes. : it is 0, so bits and bits. : it is 3, so bits and . With we found 2.217 bits ().
Exercise 3 (the memorizer’s code length). Explain the memorizer’s training bits (13.1) from first principles. What would they be with training images?
Answer
For a training image seen times, . If all images were distinct this would be ; repeated images (big shapes have few positions) have and cost less, giving the average 13.1. With it would grow towards minus the effect of more repeats — the memorizer’s training cost grows with data while its test cost falls only through overlap.
Exercise 4 (derivation: cross-entropy = entropy + KL). Show that and conclude that no model can have expected test bits below . Use it to state how far (in KL) the 23-neighbour context model is from the truth.
Answer
. KL is (Jensen’s inequality: ), with equality iff . For the 23-neighbour model, bits per image (test-set estimate).
Exercise 5 (derivation: the mixture bound). Prove for the Bayesian mixture of §5.6 with uniform prior weights. What changes with prior weights ? Why does the bound make the choice of a trade-off?
Answer
With the posterior-weighted predictions, the product of the mixture’s per-step probabilities telescopes to (each step multiplies by , and ). Since all terms are non-negative, for every , so . Uniform gives . With general priors, expert costs at most extra: a prior is a “code” for choosing the expert. More experts cover more situations (a better best expert) but the price grows — a Bayesian version of model selection.
Exercise 6 (no universal compressor). Prove that no lossless compressor can make every 288-bit string shorter. Then explain why a compressor that shortens ShapeWorld images to ~18 bits must make most other 288-bit strings longer than 288 bits.
Answer
There are inputs and only shorter strings, so two inputs would share an output (pigeonhole) and could not both be decoded. For the second part: a prefix-free code satisfies Kraft’s inequality (Lecture 20). Giving ShapeWorld images lengths of ~18 bits uses up of the budget — so even ShapeWorld images cannot all get 18 bits: rare ones get more (the code lengths are , from 11.8 bits for two huge identical shapes to 23 bits for two tiny different ones). Everything that is not a ShapeWorld image has under the true model and cannot be coded at all; a practical coder reserves a little probability for them (an escape), making them cost more than 288 bits.
Exercise 7 (LeCun’s cake for ImageNet). Using the numbers of §3.2, how many ImageNet labels carry as many bits as one 64×64 ImageNet image? Why is this an upper bound on the image’s information, and in what sense is it misleading?
Answer
labels. It is an upper bound because 3.44 bits/dim is the code length of one particular model; the true entropy can only be lower. It is misleading because many of those bits describe details (noise, texture) that no downstream task needs; the label’s 10 bits are exactly the ones a classifier needs. The cake argues for quantity of signal, not its relevance.
Exercise 8 (frozen vs fine-tuned). In §6.4, fine-tuning loses to the frozen probe at 1 label per class but wins from 3 labels per class. Explain why, in terms of the number of parameters being adapted and the number of labeled examples.
Answer
The linear probe adapts parameters from 8 examples with strong regularization; the representation stays as the puzzle shaped it. Fine-tuning adapts all ~56,000 parameters of the CNN from 8 examples: the network can fit the 8 labels in ways that distort the useful features (over-fitting, high variance between draws). With 24 or more labeled examples, the benefit of adapting the features to the task outweighs that variance. This is a bias–variance trade-off in “how much of the network to adapt”.
Exercise 9 (why the naive transfer failed). In §5.6, pretraining on unrelated arithmetic () cost less than pretraining on related captions () over 1,000 lines (0.358 vs 0.856 bits/char). Explain this paradox using the n-gram contexts.
Answer
Arithmetic lines use digits and ”+=”, which never occur in captions, so their counts live in contexts that never visits; they only distort the shortest (order 0–1) contexts slightly, and quickly builds its own longer contexts. Plain captions share many contexts with (“left”, “huge”, “ring”) but continue them differently (” and a” vs ”:”, “at the top” vs ”, top”), and 20,000 lines of confident counts in exactly those contexts must be out-voted. Interference requires overlap: partly related data can hurt more than unrelated data.
Exercise 10 (thought experiment: Kolmogorov). Explain why is uncomputable (Berry’s paradox) and why, nevertheless, every model in this course gives a computable upper bound on of the training data.
Answer
If a program K(x) existed, the program “enumerate strings in order and print the first with K(x) ” would have length about , yet print a string whose shortest program is longer than — a contradiction. Upper bound: “decoder program + model parameters + arithmetic code of the data” is a program that prints the data, so its length bounds . This is the idea behind minimum description length (MDL) and behind the prequential code length used in §5.6, which avoids even having to transmit the parameters.
12. Further reading
Works shown on the Lecture 1 slides
- G. E. Hinton, S. Osindero, Y.-W. Teh. A fast learning algorithm for deep belief nets. Neural Computation, 2006.
- D. P. Kingma, M. Welling. Auto-Encoding Variational Bayes. 2013.
- I. Goodfellow et al. Generative Adversarial Nets. NeurIPS 2014.
- A. Radford, L. Metz, S. Chintala. Unsupervised Representation Learning with Deep Convolutional GANs (DCGAN). 2015.
- C. Ledig, L. Theis, F. Huszár et al. Photo-Realistic Single Image Super-Resolution Using a GAN. CVPR 2017.
- J.-Y. Zhu, T. Park, P. Isola, A. A. Efros. Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks (CycleGAN). ICCV 2017.
- A. Brock, J. Donahue, K. Simonyan. Large Scale GAN Training for High Fidelity Natural Image Synthesis (BigGAN). 2018.
- T. Karras, S. Laine, T. Aila. A Style-Based Generator Architecture for GANs (StyleGAN). 2018.
- J. Ho, A. Jain, P. Abbeel. Denoising Diffusion Probabilistic Models. NeurIPS 2020.
- A. van den Oord et al. WaveNet: A Generative Model for Raw Audio. 2016 (and Parallel WaveNet, 2018).
- J. Shen et al. Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions (Tacotron 2). 2018.
- J. Copet et al. Simple and Controllable Music Generation (MusicGen / AudioCraft). 2023.
- A. Clark, J. Donahue, K. Simonyan. Adversarial Video Generation on Complex Datasets (DVD-GAN). 2019.
- R. Girdhar et al. Emu Video: Factorizing Text-to-Video Generation by Explicit Image Conditioning. 2023.
- D. Kondratyuk et al. VideoPoet: A Large Language Model for Zero-Shot Video Generation. 2023.
- M. Yang et al. UniSim: Learning Interactive Real-World Simulators. 2023.
- A. Karpathy. The Unreasonable Effectiveness of Recurrent Neural Networks (char-rnn), 2015.
- A. Radford et al. Language Models are Unsupervised Multitask Learners (GPT-2). 2019.
- K. Schwarz et al. GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis. 2020; J. Gao et al. GET3D. 2022.
- J. Jumper et al. Highly accurate protein structure prediction with AlphaFold. Nature, 2021.
- R. Bommasani et al. On the Opportunities and Risks of Foundation Models. 2021.
- A. Radford, R. Józefowicz, I. Sutskever. Learning to Generate Reviews and Discovering Sentiment. 2017.
- J. Devlin et al. BERT. 2018; the GLUE benchmark leaderboard.
- H. Touvron et al. Llama 2. 2023; T. Kojima et al. Large Language Models are Zero-Shot Reasoners. 2022.
- O. J. Hénaff, A. Srinivas et al. Data-Efficient Image Recognition with Contrastive Predictive Coding. 2019.
- K. He et al. Masked Autoencoders Are Scalable Vision Learners. 2021.
- Y. LeCun. NeurIPS 2016 keynote (“the cake”).
Added by these notes
- C. E. Shannon. A Mathematical Theory of Communication. 1948 — entropy and the source-coding theorem.
- T. M. Cover, J. A. Thomas. Elements of Information Theory, chapters 2 and 5 (entropy, data compression) and 14 (Kolmogorov complexity).
- I. H. Witten, R. M. Neal, J. G. Cleary. Arithmetic Coding for Data Compression. Communications of the ACM, 1987 — the coder in
coding.py. - M. Li, P. Vitányi. An Introduction to Kolmogorov Complexity and Its Applications — the invariance theorem, conditional complexity, algorithmic mutual information.
- R. J. Solomonoff. A Formal Theory of Inductive Inference. 1964; M. Hutter. Universal Artificial Intelligence (AIXI), 2005.
- A. P. Dawid. Present Position and Potential Developments: Some Personal Views — Statistical Theory, the Prequential Approach. 1984 — prequential (predictive sequential) evaluation.
- L. Blier, Y. Ollivier. The Description Length of Deep Learning Models. NeurIPS 2018 — prequential code lengths of neural networks are short, connecting MDL to deep learning.
- L. Theis, A. van den Oord, M. Bethge. A Note on the Evaluation of Generative Models. ICLR 2016 — why likelihood and sample quality can disagree.
- T. Chen, S. Kornblith, M. Norouzi, G. Hinton. A Simple Framework for Contrastive Learning of Visual Representations (SimCLR). 2020; K. He et al. Momentum Contrast (MoCo). 2019 — the contrastive puzzle of §6.
- G. Delétang et al. Language Modeling Is Compression. 2023 — large language models used as general-purpose compressors.
13. Next lecture
Lecture 2 starts the technical part with the simplest possible setting: one-dimensional discrete data (HW1 Q1). We will:
- fit a histogram — the memorizer of §4, but for one variable — and see it fail to generalize when data are few;
- introduce parameterized distributions and maximum likelihood, prove that it minimizes the KL divergence to the empirical distribution (the identity of Exercise 4), and solve it with stochastic gradient descent;
- see why discrete data are best modeled with the CDF of a continuous distribution (the discretized logistic mixture of PixelCNN++), and what goes wrong with “density at the bin center × bin width”;
- count the bins of a high-dimensional histogram (the curse of dimensionality: for binary MNIST) and meet the chain rule as the way out — the starting point of the autoregressive models of Lectures 3–4, which will finally attack the 17.80-bit floor of ShapeWorld with neural networks.