← Explainer Library

Interactive Explainer

Guidance Bends the Trajectory

A diffusion model generates by starting from pure noise and running a learned reverse process that walks each sample back toward the data. Left alone it is unconditional — samples scatter across every mode. Add a guidance term pointing at a chosen class and the trajectories bend toward it. Turn the knob up and they bend harder… and collapse onto the class's centre. Fidelity up, diversity down. Watch it happen below.

Prelude

Sampling is following a score

The reverse process moves a sample $x$ in the direction of the score $\nabla_x \log p(x)$ — uphill in probability — while slowly removing noise. That unconditional score pulls each sample toward whichever data mode is nearest, so a batch ends up spread over all the modes.

To condition on a class $c$ we want the score of $p(x \mid c)$. Bayes' rule splits it into the unconditional score plus the gradient of a classifier, and guidance simply over-weights that second term by a scale $w$:

$$\nabla_x \log p(x \mid c) = \nabla_x \log p(x) + \nabla_x \log p(c \mid x),$$ $$\tilde{s}(x) = \nabla_x \log p(x) + w\,\nabla_x \log p(c \mid x).$$

At $w = 0$ the class term vanishes and you sample unconditionally. As $w$ grows the pull toward class $c$ dominates — the mechanism behind classifier and classifier-free guidance alike.

The Lab

Turn the knob, watch the pull

Three class blobs sit in the plane (the data distribution). Press Run and a batch of noisy samples runs the reverse process, leaving faint trails. With guidance $w = 0$ they settle across all three blobs. Raise the guidance scale and pick a target class: the trajectories bend toward that blob. Push $w$ high and they pile onto its centre — sharp, on-class, and nearly identical.

Large rings are the three class blobs; the selected one is highlighted. Dots are samples; faint lines are their reverse-diffusion trajectories from noise to data. Change $w$ or the target and press Run to resample.
On-target fidelity
Sample diversity (spread)
Guidance scale $w$
Sweep $w$ from 0 upward and re-run. Watch the two numbers move in opposite directions: fidelity (fraction landing on the target class) climbs while diversity (how spread out the samples are) falls. That trade is the signature of guidance — there is no setting that maximizes both.
The Payoff

Fidelity and diversity pull against each other

Guidance re-weights the sampling distribution toward roughly $p(x)\,p(c\mid x)^{w}$. A larger exponent sharpens the class posterior: probability mass concentrates where the classifier is most confident — the centre of the target blob. That is exactly what you want for fidelity (samples unmistakably belong to the class) and exactly what destroys diversity (the tails and neighbouring modes get starved).

Classifier-free guidance. Rather than train a separate noisy-image classifier, modern systems train one network to predict both the conditional and unconditional score (by randomly dropping the label). At sampling time they extrapolate $\tilde{\varepsilon} = (1{+}w)\,\varepsilon_c - w\,\varepsilon_{\varnothing}$, reaching the same bent trajectories with no extra classifier. Same knob, same trade-off — this is the guidance scale you set in Stable Diffusion or Imagen.