Generative Models: The Big Picture
A map of the five families of generative models (autoregressive, VAE, GAN, diffusion and flow) and the trade-offs between likelihood, sample quality, speed and control.
In Module 07 (Transformers & LLMs) you studied one generative model in great depth: the decoder-only transformer, which writes text one token at a time. But text is only one kind of data. The same field produced models that paint photorealistic images from a sentence, clone a voice from a few seconds of audio, and generate minutes of coherent video. This module opens those boxes.
The good news: there are only a handful of core ideas. Every modern generator, whether it makes text, images, sound or video, is built from one or two of five families. This lesson draws the map. The rest of the module zooms into each region.
What is a generative model?
A discriminative model learns : given an image, what label? A generative model learns the data distribution itself, , or a conditional version where is a prompt, class label or another image. Once you have it you can:
- Sample: draw new x that look like the training data.
- Score: ask how probable a given x is (only some families can do this).
- Condition and edit: generate x given c, or fill in missing parts of x.
- Represent: some families learn a compact latent z that captures the meaning of x.
The difficulty is dimension. A 1024Γ1024 RGB image is about three million numbers. Real images occupy a vanishingly thin, curved region (a "manifold") inside that space. A generative model must find that region and learn how probability is spread across it, from finite samples.
There are two broad strategies:
- Explicit density: write down a and maximize the likelihood of the data. Autoregressive models, normalizing flows and VAEs (via a lower bound) do this.
- Implicit or sampler-based: never write down p(x); instead learn a procedure that transforms simple noise into data. GANs do this. Diffusion and flow-matching models sit in between: they learn a noise-to-data process, and you can compute likelihoods for them, but in practice they are trained and used as samplers.
The five families
The diagram splits the families by whether they model the density explicitly or learn a noise-to-data sampler; diffusion and flow matching are linked because, as you will see in lesson 4, they are two views of the same idea.
1. Autoregressive models
Use the chain rule of probability to factor the joint distribution into a product of conditionals:
Taking logs turns the product into a sum, , which is exactly the cross-entropy loss you minimized for LLMs.
A network (today, a transformer) predicts each element given the previous ones. Training is plain cross-entropy, the likelihood is exact, and conditioning is natural: put the prompt first. This is how LLMs work, and also how early image models (PixelRNN/PixelCNN, 2016) and audio models (WaveNet, 2016) worked on raw pixels and waveform samples.
The catch is sequential sampling: T elements means T network calls. That is fine for a few thousand text tokens but painful for millions of pixels. The modern fix is to first compress media into a short sequence of discrete tokens with a learned tokenizer (VQ-VAE, 2017; VQGAN, 2020; neural audio codecs), then model those tokens autoregressively. Many speech and "any-to-any" multimodal models work this way.
2. Variational autoencoders (VAEs)
Assume each x was generated from a hidden latent z: sample z from a simple prior, then decode. The exact likelihood requires integrating over all z, which is intractable, so VAEs maximize a lower bound (the ELBO). They give you a smooth, meaningful latent space and fast one-step sampling, but on their own their samples tend to be blurry. Their biggest role today is as the compressor in front of diffusion models. Lesson 2.
3. Generative adversarial networks (GANs)
A generator turns noise into samples; a discriminator tries to tell real from fake; they are trained against each other. GANs produce sharp images in one forward pass and dominated image synthesis from roughly 2017 to 2021 (StyleGAN). But training is unstable and they tend to mode collapse, generating a narrow slice of the data. Lesson 3.
4. Diffusion models
Define a fixed forward process that gradually adds Gaussian noise until the data is pure noise. Train a network to undo one small step of noise, which turns out to be a simple regression: predict the noise that was added. To generate, start from noise and denoise step by step. Stable training, excellent coverage, and natural ways to steer with text make this the dominant approach for images, video and increasingly audio. Lesson 4.
5. Normalizing flows and flow matching
Classic normalizing flows (RealNVP, 2016; Glow, 2018) build an invertible network f from data to noise. The change-of-variables formula gives an exact likelihood:
The second term measures how much stretches or squeezes volume around : probability mass is conserved, so a region that compresses must have proportionally higher density.
The invertibility and cheap-determinant requirements restrict the architecture, which held back sample quality. Flow matching and rectified flow (both 2022) keep the "transport noise to data" idea but drop invertible layers: they learn a velocity field that moves samples along nearly straight paths from noise to data, trained with a regression loss very much like diffusion. Several leading open image models now use it. Lesson 4 covers it alongside diffusion.
A worked example: exact likelihood with an autoregressive model
To make "explicit likelihood" concrete, here is the smallest possible autoregressive model, a character bigram, trained by counting. It scores strings exactly with the chain rule and samples one character at a time.
import numpy as np
train = "the cat sat on the mat. the dog sat on the log. " * 20
test_good = "the dog sat on the mat."
test_words = "mat the on sat dog the." # same words, shuffled order
test_chars = "hte gdo ast no eht tma." # letters shuffled inside words
vocab = sorted(set(train))
idx = {c: i for i, c in enumerate(vocab)}
V = len(vocab)
# Bigram model p(x_t | x_{t-1}) with add-one smoothing
counts = np.ones((V, V))
for a, b in zip(train, train[1:]):
counts[idx[a], idx[b]] += 1
probs = counts / counts.sum(axis=1, keepdims=True)
def bits_per_char(s):
# chain rule: log p(x) = sum_t log p(x_t | x_{t-1}) -> exact likelihood
lp = sum(np.log2(probs[idx[a], idx[b]]) for a, b in zip(s, s[1:]))
return -lp / (len(s) - 1)
print(f"uniform baseline: {np.log2(V):.2f} bits/char")
print(f"'{test_good}': {bits_per_char(test_good):.2f} bits/char")
print(f"'{test_words}': {bits_per_char(test_words):.2f} bits/char")
print(f"'{test_chars}': {bits_per_char(test_chars):.2f} bits/char")
# Sampling is sequential: one token at a time
rng = np.random.default_rng(0)
c, out = "t", "t"
for _ in range(40):
c = vocab[rng.choice(V, p=probs[idx[c]])]
out += c
print("sample:", out)
Expected output: about 3.81 bits/char for uniform guessing, about 1.28 for the real sentence, about 1.41 for the word-shuffled one, and about 5.28 for the letter-shuffled one. Two lessons hide in those numbers. First, an exact likelihood is a precise, comparable score for any input. Second, the model's context limits what the likelihood can notice: a bigram only sees one previous character, so it barely penalizes shuffled word order. Scale the context and the network (a transformer) and you get an LLM.
The trade-off space
No family wins on every axis. A useful mental table:
| Family | Exact likelihood? | Sample quality (images) | Sampling speed | Training stability | Mode coverage | Useful latent? |
|---|---|---|---|---|---|---|
| Autoregressive | Yes | High, with good tokenizers | Slow (sequential) | Very stable | Good | No (unless tokenized) |
| VAE | Lower bound | Blurry alone | Fast (one pass) | Stable | Good | Yes |
| GAN | No | Sharp | Fast (one pass) | Fragile | Often poor | Somewhat |
| Diffusion | Bound / computable | Excellent | Many steps (reducible) | Very stable | Good | Noise space only |
| Flow matching | Computable via ODE | Excellent | Fewer steps than diffusion | Very stable | Good | Noise space only |
Real systems mix families. A typical text-to-image model is a VAE (compressor) + a diffusion or flow model (generator) + a transformer (the denoiser network and the text encoder). Many video models are the same with a 3-D latent. Speech systems often pair an autoregressive model over audio tokens with a neural codec decoder.
The diagram shows how the families combine at generation time in a typical text-to-image model: a transformer encodes the prompt, a diffusion or flow model turns random noise into a clean latent under that conditioning, and the VAE decoder from lesson 2 turns the latent into pixels. Each box is one of the next three lessons.
The sampling-speed column is not academic: for media generators it sets the cost per output. A model that needs 50 network evaluations per image costs roughly 50 times more compute per image than a one-step model of the same size, which is why step-reducing distillation matters so much commercially. Module 12 (AI Cost Optimization) returns to these levers.
Likelihood versus sample quality
It is tempting to assume that the model with the best likelihood makes the best samples. It does not have to. Theis, van den Oord and Bethge's "A note on the evaluation of generative models" (2015) showed the two can be nearly independent:
- Likelihood is mode-covering. Maximum likelihood minimizes , which heavily penalizes assigning near-zero probability anywhere the data lives. A model will spread mass widely, including over blurry in-between images, rather than miss a mode.
- Likelihood counts every bit equally. Most of the information in a photo is imperceptible noise and texture detail. A model can win on likelihood by modelling sensor noise perfectly while getting faces wrong.
- Humans judge individual samples. A GAN that produces 10 kinds of perfect faces and ignores the rest can look better to a human than a high-likelihood model, while being worse at covering the distribution.
That is why image generation is evaluated with sample-based metrics: FID (FrΓ©chet Inception Distance, from "GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium", 2017) compares statistics of real and generated images in a pretrained network's feature space; CLIP score checks prompt alignment; and, increasingly, human preference studies and arena-style leaderboards, because automatic metrics correlate imperfectly with what people prefer. Text models, by contrast, are still routinely compared by perplexity (an exact likelihood) during pretraining, because there the likelihood is tightly tied to downstream ability.
Note: Precision and recall versions of FID-style metrics separate the two failure modes: low precision means unrealistic samples; low recall means missing modes (mode collapse). Always ask which one a single headline number hides.
Pitfalls and misconceptions
- "Diffusion models don't have a likelihood." They do: you can compute a bound, or an exact value via the probability-flow ODE. It is just not how they are usually judged.
- "GANs are dead." As full generators they have largely been displaced, but adversarial losses survive inside other systems: autoencoder training for latent diffusion uses a GAN-style loss for sharpness, and some few-step distillation methods use adversarial objectives.
- "Autoregressive means text." Autoregression is a factorization, not a modality. Images, audio and actions can all be tokenized and modelled that way.
- One metric to rule them all. FID depends on sample count, image resolution and the feature network. Never compare FIDs computed with different protocols.
Hands-on exercise
- Run the bigram example. Add a trigram model (condition on two previous characters) and recompute bits per character on the three test strings. Which test string benefits most from the extra context, and why?
- Replace
rng.choice(V, p=...)with greedy decoding (argmax). Describe what happens to the sample, and connect it to the softmax-temperature ideas from Module 07. - On paper, fill in the trade-off table for a hypothetical "VAE + diffusion in latent space" system. Which column does each component improve?
- Find a current text-to-image leaderboard or model card. Note which metric is used (FID, human preference, something else) and write two sentences on what it would miss.
Expected outcome: the trigram lowers bits per character on the real sentence noticeably and makes samples more word-like; greedy decoding gets stuck in a repetitive loop; you can explain why likelihood and visual quality need separate evaluation.
Key takeaways
- A generative model learns or ; the five families are autoregressive, VAE, GAN, diffusion and flow (including flow matching).
- Autoregressive models give exact likelihoods but sample sequentially; tokenizers make them practical for media.
- VAEs learn a latent space and now mostly serve as compressors; GANs are sharp and fast but unstable and prone to mode collapse.
- Diffusion and flow matching turn generation into a stable regression problem and dominate images and video.
- Likelihood and sample quality are different goals: evaluate media generators with sample-based metrics and human preference, and know what each metric hides.
- Real systems combine families: compressor + generator + transformer backbone + text encoder.
Next, we open the first of those components: the autoencoder, its probabilistic cousin the VAE, and the autoencoder that sits at the front of latent diffusion.
Further reading
- "A note on the evaluation of generative models", Theis, van den Oord and Bethge (2015).
- "Deep Generative Modelling: A Comparative Review of VAEs, GANs, Normalizing Flows, Energy-Based and Autoregressive Models", Bond-Taylor et al. (2021).
- Stanford CS236 "Deep Generative Models" course notes (Stefano Ermon).
- "Neural Discrete Representation Learning" (VQ-VAE), van den Oord, Vinyals and Kavukcuoglu (2017).
Save your progress and earn XP
Create a free account to take the quiz, track progress and unlock badges.