4.5.13 · D2Generative Models

Visual walkthrough — Score-based generative models

2,136 words10 min readBack to topic

We link back to the parent Score-based generative models and lean on Langevin Dynamics, Stochastic Differential Equations, and the cousin idea in Diffusion Models.


Step 1 — A cloud of points and the "uphill arrow"

WHY. Generative modelling means: invent new dots that look like they belong to this pile. One way is to know the height of the pile everywhere. But a cheaper way is to know, at any spot you stand, which way is uphill — the direction that leads toward thicker piles. Follow those arrows and you walk from empty desert into the crowd. That arrow field is the whole game.

PICTURE. Below, black dots are data. Stand anywhere; the red arrow points toward denser data. That red arrow is what we will call the score.

Gradient of what, and why an arrow?
Gradient collects the slope of in each direction into one arrow pointing the steepest-uphill way. For a scalar height field, that arrow is "which way is up."

Step 2 — Why the log, and why the normalizer vanishes

WHY. Real densities are written .

  • — an unnormalized score of plausibility we can compute (e.g. , see Energy-Based Models).
  • — the partition function, the total volume under . In high dimensions this integral is hopeless.

Watch what the log does:

  • turned the division by into a subtraction of .
  • of a constant is zero, so evaporates.

PICTURE. Multiplying the whole pile by rescales every height by the same factor — it never changes which way is uphill. The red uphill arrows are identical before and after normalizing.


Step 3 — The wall: we still don't know the true score

WHY / the naïve objective. Measure disagreement as squared arrow-difference, averaged over data:

  • — the network's arrow, tunable via weights .
  • — squared length of the gap arrow; zero only when the two arrows match exactly.
  • — average over places where real data actually sits.

The wall: the second term is the very thing we don't have. We have samples from , not its formula, so we cannot compute its gradient.

PICTURE. We can see dots (samples) but not the smooth height surface behind them. Asking for its gradient at a lonely dot is undefined — the surface is invisible.


Step 4 — The trick: blur the pile with Gaussian noise

WHY. A smooth cloud has a well-defined score everywhere — even in the deserts, because the blur leaks probability outward. And, as Step 5 shows, for Gaussian blur we know the score exactly.

The kick:

  • — a clean data point.
  • — a random push, each coordinate an independent standard bell-curve draw.
  • — how hard we push (the noise scale). Big = heavy blur; = original data.
  • — the noisy point we actually feed the network.

PICTURE. Left: sharp dots. Right: the same dots each nudged by a red arrow , producing a soft haze whose height surface is smooth.


Step 5 — The exact score of one Gaussian blur

WHY this is computable. Start from the log of a Gaussian:

  • — squared distance from the fuzzy point to the true center.
  • The minus sign — far from center means lower log-probability (a downhill bowl).
  • — collects and the factors; gradient kills it.

Now take the gradient with respect to (derivative of is ):

Substitute the kick :

  • — the uphill arrow points opposite the noise you added, scaled by . It says: "to climb back to the clean point, undo the kick."

PICTURE. The noise pushed the point out (black arrow); the score points back in toward (red arrow) — exactly antiparallel.

Why is the score bigger when is smaller?
Because blows up: a sharp Gaussian is steep, so its uphill arrows are long; a wide Gaussian is gentle, arrows short.

Step 6 — From one point's score to the whole cloud's score

WHY (the denoising objective). Replace the unknown true score in Step 3 with the known per-point score. The new objective:

  • — the noisy input the network sees.
  • — adding this equals subtracting the target ; the bracket is zero when .
  • Averaging over both and — the key. For a fixed noisy point , many different pairs could have produced it. The squared error is minimized by the average of their targets, and that average is exactly — the marginal score.

So: the best possible network output at is the average over all clean points that might have landed there, which is precisely the true smoothed score. The per-point noise is a proxy whose expectation is the truth.

PICTURE. One noisy point (center) could have come from several clean dots. Their individual back-arrows (grey) average to one red arrow — the marginal score the network converges to.


Step 7 — Edge cases: too big, too small

Case (barely any noise). The cloud is razor-sharp, back on the true data manifold. But then the desert between modes stays empty: if you start sampling out there, the score is (flat, no signal) and you never find the data. Also the target explodes, giving huge, unstable gradients.

Case large (heavy blur). Now the whole space is gently sloped — great for connectivity, you always feel some uphill pull — but the fine structure of the data is smeared away, so samples come out blurry.

The fix (multi-scale). Use a ladder of noise levels and one noise-conditional network that is told which rung it is on:

  • weight — cancels the blow-up in the target magnitude so every rung contributes comparably. Without it, large- rungs are ignored.

PICTURE. Three panels: heavy blur (connected but coarse) → medium → light (sharp but isolated). The red arrow field grows sharper and more detailed as shrinks.


Step 8 — Using the arrows: walk uphill with a wobble

WHY the jiggle. Pure uphill steps collapse onto the single highest peak (one image forever). The controlled noise (from Langevin Dynamics) lets you sample the whole distribution instead of only its summit. This is a discretization of the Langevin SDE :

  • — step size; shrink it as shrinks (finer moves near the data).
  • — the exact noise scale that makes the walk settle onto (detailed balance).
  • Annealing: run this at (coarse exploration), then down to (fine polish), carrying over between rungs.

PICTURE. A red trajectory zig-zags from an outer noisy start, guided by the arrow field, wobbling but steadily drifting into a data mode.


The one-picture summary

Everything on one canvas: clean data → blur into a smooth cloud whose per-point score is → a network averages those to learn the true marginal arrows across a ladder of scales → annealed Langevin walks the red arrows from noise back to data.

Recall Feynman retelling — say it back in plain words

Real data is a pile of dots. We don't want the pile's exact height, just which way is uphill everywhere — that arrow is the score, and taking the gradient of the log makes the impossible normalizing constant vanish. But the true arrows are hidden because we only see scattered dots. So we cheat: kick every dot with a bit of Gaussian noise. For a single kicked dot, the uphill arrow is trivial — it just points back opposite the kick, namely . Train a network to output that back-arrow from the noisy dot; because many clean dots could produce the same noisy dot, the network is forced to output their average back-arrow, which is exactly the true smoothed score. One kick level is too crude, so we use a ladder of noise scales (big for connectivity, small for detail) with a weight so no rung is ignored. Finally, to make new data, start in noise and step uphill along the arrows with a little random wobble, cooling the noise level down — and you walk out a fresh, realistic sample.