Section 2: The general principle of generative models
Pick a parametric family, define a divergence, and minimise it using only samples.
I am working through Mathematical Foundations of Generative AI, Prof. Prathosh AP’s public lectures. The playlist is the spine. These notes are my deep dive on each section: a visual when the picture is the point, a detour when a prerequisite is doing real work, and every formula read aloud with a plain-words line right after it.
Previously: Section 1: The dataset and the problem.
Symbol cheat-sheet
| Symbol | Say it as | In plain words |
|---|---|---|
| ”z” | a random input vector (noise seed) fed into the generator | |
| ”script Z” | the space of possible noise seeds (usually ) | |
| “script X” | the space of possible data points (usually ) | |
| “k much smaller than d” | the noise seed has far fewer numbers than a full image | |
| ”normal with mean mu and variance sigma-squared” | a 1-D bell curve centred at with spread | |
| “standard normal” | a bell curve centred at zero with spread 1 in every coordinate, and no correlation between coordinates | |
| ”capital I (identity matrix)“ | a grid of 1s on the diagonal and 0s elsewhere | |
| ”g-theta maps script-Z to script-X” | a neural network with weights that takes noise and outputs a synthetic data point | |
| “theta” | the adjustable knobs (weights) of the generator network | |
| ”theta-star” | the best knob setting found after training | |
| ”P-theta” | the distribution of outputs produced when random noise is pushed through | |
| “is defined as” | this symbol on the left is shorthand for the thing on the right | |
| ”divergence of P-x from P-theta” | a non-negative score measuring how different the real distribution is from the model distribution | |
| ”minimum over theta” | the smallest score achievable by tuning | |
| “arg-min over theta” | the knob setting that achieves that smallest score | |
| ”if and only if” | each side guarantees the other |
Section 2: The general principle of generative models
Section 1 left me with a vague goal: estimate and learn to sample from it. This section turns that goal into a three-step recipe. Every later model in the lectures is this recipe with different choices plugged in.
The statement I am carrying:
(i) Assume a parametric family on , denoted , represented using deep neural networks. (ii) Define and estimate a divergence between and . (iii) Solve an optimisation problem over the parameters of to minimise that divergence.
The concrete version: draw , pass it through a network , and call the distribution of by the name . Then solve
Read aloud: “theta-star equals the arg-min over theta of the divergence between and .”
In plain words: find the network weights that make the gap between the real data distribution and the model’s output distribution as small as possible.
After that, sampling and computing gives samples from , which is as close to as this family could get.
1. Intuition first
I cannot see . So I build a machine with knobs, , that turns plain random noise into data-shaped outputs. I keep turning the knobs until the machine’s output distribution looks as close as possible to the real data. The “how close” score is a divergence. The knob-turning is optimisation.
2. Real-world analogy
The traffic generator from Section 1 takes random seeds and outputs synthetic requests. It has configuration knobs: endpoint weights, payload-size parameters, and so on.
| Load-testing analogy | Notation | In plain words |
|---|---|---|
| Random seed fed into the generator | a fresh roll of standard random numbers | |
| The generator code | the neural network that turns seeds into outputs | |
| Its config knobs | the network weights we can tune | |
| The distribution of traffic it produces | what the generator’s outputs look like overall | |
| Score of how different synthetic traffic is from real logs | the mismatch score (0 means identical) | |
| Tuning knobs until that score is near zero | training the model |
The hard step is computing the score: I cannot see the true user-behaviour formula, only the access log. That difficulty drives the rest of Week 1.
3. Visual
One dimension is enough to see the recipe. The noise is . The network is the simplest one I can write, , so . The green curve is the target . The blue curve is , what this generator can produce.
Three things to watch while moving the sliders:
- Single bump: and drive the divergence to 0. The target is a bell centred at 2 with spread 0.6, and produces that exact bell.
- Two bumps: the divergence never reaches 0 for any . The closest blue curve is one wide bell stretched over both humps. A linear can only shift and stretch a single bell; it can never split it into two. That is why we need a deep, non-linear neural network.
- Why this widget is cheating: it draws the green curve and computes the divergence directly because the target formula was hardcoded into the demo. In real life we only get samples.
4. The formula, decoded
Read aloud: “theta-star equals the arg-min over theta of the divergence of from , where is defined as the distribution of when is drawn from a standard normal.”
In plain words: draw standard random noise , push it through the network , and adjust the weights until the resulting distribution is as close as possible to the real data distribution .
Piece by piece:
| Symbol | What it is | Type / shape | In plain words |
|---|---|---|---|
| input noise | vector in , usually | the random seed | |
| standard Gaussian | distribution on | an easy-to-sample source of randomness | |
| generator | function (neural net) | reshapes noise into data | |
| generator parameters | vector of weights | the knobs we tune during training | |
| model distribution | distribution on , implicit | what the generator’s outputs look like as a whole | |
| true distribution | distribution on , unknown | the target we want to match | |
| divergence | maps two distributions to a number | the “how far apart” score | |
| optimal parameters | same shape as | the trained generator weights |
Detour 1: The standard Gaussian
In one dimension, is the familiar bell curve centred at with spread . “Standard” means centred at zero with unit spread:
Read aloud: ” is drawn from a normal distribution with mean 0 and variance 1.”
In plain words: is a single random number that usually lands near 0 (mostly between and ).
In dimensions, stacks of those independent standard bells into a vector:
Read aloud: “the vector is drawn from a -dimensional standard normal distribution.”
In plain words: roll independent standard bell-curve numbers and pack them into a list. We use it as input noise because every software library can sample it instantly, and it has no built-in image structure — any structure in had to be learned by .
Back to the main thread. is our raw clay; is the sculptor.
Detour 2: Pushing a random variable through a function
If is random and you compute , then is random too, with a new distribution shaped by .
In the 1-D linear case:
Read aloud: “if is standard normal, then follows a normal distribution with mean and variance .”
In plain words: multiplying by stretches the bell’s width by , and adding slides its centre to . That is what the two sliders in the widget do.
A deep, non-linear network can bend and fold the bell into multiple humps or into the thin space of human faces. We call that resulting output distribution . For a deep network we almost never have a closed-form formula for — we only know how to sample from it (draw , run ).
Back to the main thread. Because has no formula we can evaluate, we call it an implicit distribution.
Detour 3: Divergence (weaker than a distance)
A divergence scores how different two distributions are. It must obey two rules:
Read aloud: “the divergence of from is at least zero, and it equals zero if and only if equals .”
In plain words: the score can never be negative, and it hits zero only when the model matches reality everywhere.
Unlike a ruler distance, a divergence does not have to be symmetric:
Read aloud: “the divergence of from is not necessarily equal to the divergence of from .”
In plain words: order matters, which is why we write a double bar instead of a comma.
Back to the main thread. Those two rules make “minimise ” a clean training objective: the floor is 0, and hitting the floor means we solved the problem.
Detour 4: vs
For a bowl-shaped function like :
Read aloud: “the minimum over theta of is 1, while the arg-min over theta of is 3.”
In plain words: asks “how low does the curve go?” (answer: height 1), whereas asks “what knob setting puts me at that lowest point?” (answer: ).
Back to the main thread. At the end of training we want to keep the trained weights , so the principle writes .
5. Tiny worked example
First, see how pushes noise into outputs. Take and , so :
Read aloud: “feeding inputs into produces outputs .”
In plain words: the network stretches the spacing by 2 and shifts the centre to 3, so standard normal draws become draws from .
Second, see how a divergence scores different models on a two-outcome coin world. Let the real coin be fair, , and score candidate models with the KL divergence (derived in Section 3a):
Read aloud: “the KL divergence is 0.5 times the natural log of 0.5 over , plus 0.5 times the natural log of 0.5 over .”
In plain words: average the log mismatch across the two coin faces.
| Candidate model | Calculation | Divergence score | In plain words |
|---|---|---|---|
| heavily biased coin; high mismatch score | |||
| nearly fair coin; score drops close to zero | |||
| exact match; score hits its floor of zero |
Optimisation is nudging so the model moves down this table toward 0.
Four open questions this recipe leaves behind
| Open question | Why it is hard | Where the lectures answer it |
|---|---|---|
| (i) How do I compute without formulas for either distribution? | I only have real samples and generated samples | Section 3b: rewrite the divergence as expectations and estimate with sample averages |
| (ii) Which divergence should I pick? | Different divergences punish different mistakes (e.g. one wide bell vs one hump) | Section 3a (f-divergences) and Week 6 (Wasserstein) |
| (iii) How do I choose the architecture for / ? | Must be expressive enough for images/text, yet still trainable | GANs, VAEs, diffusion, transformers |
| (iv) How do I solve ? | Millions of weights, often inside a min-max game | Alternating gradient descent (Week 2 onward) |
6. Connect back
Every major model family is a row in this table:
| Model | Choice of | Divergence | Optimisation |
|---|---|---|---|
| GAN | , implicit | Jensen–Shannon (an f-divergence) | min-max game with a discriminator |
| WGAN | , implicit | Wasserstein distance | min-max game with a 1-Lipschitz critic |
| VAE | Forward KL (via the ELBO lower bound) | gradient ascent on the ELBO | |
| DDPM | reverse chain of Gaussian steps | Forward KL (via the ELBO lower bound) | regression on the added noise |
| Autoregressive / Transformer | Forward KL (maximum likelihood) | cross-entropy loss |
One identity links the bottom three rows:
Read aloud: “the theta that minimises the KL divergence from to is the exact same theta that maximises the expected log probability of real data under the model.”
In plain words: shrinking forward KL is identical to maximum likelihood — making real data look as probable as possible under your model.
Quick check (optional)
- Why can no setting of in match the two-bump target, and what has to change about ?
- After training finishes and gives you , how do you produce 10 new samples?
- If , what follows? What if the divergence is small but not zero?
Next: Section 3a: f-divergences.