v9.1.1
Menu

Chapter 4: Reverse Process & Denoising

Week 3-4

The reverse process is where the magic happens: starting from pure noise, a neural network learns to iteratively denoise, reconstructing data step by step. This chapter covers score functions, denoising score matching, the reverse SDE, the DDPM training objective, noise prediction parameterizations, and loss weighting strategies.

Topics
6
Demo
1
Videos
3
Min read
35

Chapter Overview

The forward process systematically destroys data by adding noise. The reverse process learns to undo this destruction, transforming pure Gaussian noise into structured data samples. This is the generative core of diffusion models: if we can accurately reverse each noising step, we can generate new data by starting from random noise and iteratively denoising.

The key mathematical object is the score function ∇xlog⁡pt(x)\nabla_x \log p_t(x)---the gradient of the log-density of the noisy data distribution at time tt. Anderson's theorem (1982) proves that knowing the score function at every time tt is sufficient to reverse the forward SDE exactly. Since we cannot compute the score analytically (it requires knowing the full data distribution), we train a neural network to approximate it.

Denoising score matching provides an elegant training objective: instead of estimating the score directly, we can equivalently train the network to predict the noise ϵ\epsilon that was added to a clean sample x0x_0 to produce a noisy sample xtx_t. This connection---score estimation equals noise prediction---is the foundation of DDPM and all modern diffusion models.

This chapter covers:

  • Score Functions: The gradient of the log-density and its role in generative modeling
  • Denoising Score Matching: Training neural networks to estimate scores via noise prediction
  • The Reverse SDE: Anderson's theorem and the reverse-time diffusion process
  • DDPM Training Objective: The simplified loss function that makes training practical
  • Parameterizing the Noise Predictor: ϵ\epsilon-prediction vs x0x_0-prediction vs vv-prediction
  • Loss Weighting Strategies: How different timestep weightings affect sample quality

Chapter Roadmap

Click any topic to jump in

Explainer videoInteractive demo
1
Score Functions

∇ₓ log p(x) — the key quantity defining how to reverse diffusion.

Definition and Geometric MeaningScore of a Gaussian MixtureScore for Noisy Distributions
Learning the reverse

Score matching and SDE reversal

2
Denoising Score Matching

Learning the score by predicting noise — avoiding intractable normalizing constants.

The Score Matching ObjectiveDenoising Score Matching TheoremFrom Score Matching to Noise Prediction
3
Reverse SDE

The reverse process is also an SDE, determined by forward SDE and the score.

Anderson's Reverse-Time SDEThe Probability Flow ODEDiscretizing the Reverse Process
Training in practice

Loss and architecture

4
DDPM Objective

Predicting noise ε at each timestep — equivalent to score matching.

The Variational Lower BoundSimplified Training LossVLB vs Simple Loss in Practice
5
Noise Predictor

U-Net with time embedding, self-attention, and skip connections.

Epsilon-PredictionX0-PredictionV-Prediction
Optimizing the objective
6
Loss Weighting

Uniform, SNR-weighted, min-SNR — balancing the loss across timesteps.

SNR-Based WeightingMin-SNR Loss WeightingPerceptual Loss Weighting

Topics

6 topics in this chapter

The forward-process chapter taught us to destroy data: any sample becomes pure Gaussian noise through the reparameterized kernel xt=αˉt x0+1−αˉt ϵx_t = \sqrt{\bar{\alpha}_t}\, x_0 + \sqrt{1 - \bar{\alpha}_t}\, \epsilon. Generation demands the opposite, turning noise back into data, and that reversal needs a quantity we have not yet met: the score function s(x)=∇xlog⁡p(x)s(x) = \nabla_x \log p(x), the gradient of the log-density. The problem it solves is fundamental. To sample from a distribution we would normally need its density p(x)p(x), but computing p(x)p(x) requires an intractable normalizing integral over all possible data. The score sidesteps this entirely: it points toward higher-probability regions, it can be estimated from samples alone, and the normalizing constant cancels out of the gradient. This topic first defines the score and its geometry for a single Gaussian, then examines the far richer multimodal structure of a Gaussian mixture, and finally connects the score at any noise level to the Bayesian optimal denoiser, the key identity that makes the entire reverse process learnable from data.

Definition

The score function s(x)=∇xlog⁡p(x)s(x) = \nabla_x \log p(x) is the gradient of the log-probability density with respect to xx. It is a vector field pointing toward regions of higher likelihood, independent of the intractable normalizing constant, so it can be estimated from data samples alone. Knowing the score at every noise level suffices to reverse the diffusion process.

In this topic

  1. 1Definition and Geometric Meaning
  2. 2Score of a Gaussian Mixture
  3. 3Score for Noisy Distributions
1 of 3
Definition and Geometric Meaning

s(x)=∇xlog⁡p(x)=∇xp(x)p(x)s(x) = \nabla_x \log p(x) = \frac{\nabla_x p(x)}{p(x)}

The score function is the gradient of the log-density. At any point xx in data space, it gives a vector pointing toward higher probability regions. For a Gaussian p(x)=N(x;μ,σ2I)p(x) = \mathcal{N}(x; \mu, \sigma^2 I), the score is s(x)=−(x−μ)/σ2s(x) = -(x - \mu)/\sigma^2, always pointing toward the mean μ\mu. The magnitude ∥s(x)∥\|s(x)\| is larger far from the mean (strong pull) and smaller near the mean (weak pull). This gradient field defines a vector field over the entire data space.

Mathematical Intuition

The score s(x)=∇xlog⁡p(x)=∇xp(x)/p(x)s(x) = \nabla_x \log p(x) = \nabla_x p(x)/p(x) is a vector field over the entire data space. For a Gaussian N(μ,σ2I)\mathcal{N}(\mu, \sigma^2 I), the score is −(x−μ)/σ2-(x-\mu)/\sigma^2, a linear restoring force toward the mean. Crucially, the score does not depend on the normalizing constant Z=∫p∗(x)dxZ = \int p^*(x)dx, because ∇xlog⁡(p∗/Z)=∇xlog⁡p∗\nabla_x \log(p^*/Z) = \nabla_x \log p^*. This is what makes score-based methods tractable: we avoid the intractable partition function entirely.

Example:

Compute the score function for a 1D Gaussian p(x)=N(x;3,4)p(x) = \mathcal{N}(x; 3, 4) at x=7x = 7.

2 of 3
Score of a Gaussian Mixture

∇xlog⁡p(x)=∑kπkN(x;μk,σk2) −(x−μk)σk2∑kπkN(x;μk,σk2)\nabla_x \log p(x) = \frac{\sum_k \pi_k \mathcal{N}(x; \mu_k, \sigma_k^2)\, \frac{-(x - \mu_k)}{\sigma_k^2}}{\sum_k \pi_k \mathcal{N}(x; \mu_k, \sigma_k^2)}

For a mixture of Gaussians, the score is a posterior-weighted average of the individual component scores, where the weights are the responsibilities, the probability that each component generated xx. Near component kk the score is dominated by that component's linear pull toward μk\mu_k; between components the score interpolates, steering toward whichever mode is nearest. This multimodal structure is exactly what makes score estimation hard: the network must learn a complex, spatially varying vector field with basins around every mode and unstable saddle points between them. It connects directly to the single-Gaussian case from the previous concept, which is the special one-component limit where the responsibilities collapse to one.

Mathematical Intuition

For a mixture p(x)=∑kπkN(x;μk,σk2I)p(x) = \sum_k \pi_k \mathcal{N}(x;\mu_k,\sigma_k^2 I), the score is a posterior-weighted average: ∇xlog⁡p=∑krk(x)⋅(−(x−μk)/σk2)\nabla_x \log p = \sum_k r_k(x) \cdot (-(x-\mu_k)/\sigma_k^2) where rk(x)=πkN(x;μk,σk2)/p(x)r_k(x) = \pi_k \mathcal{N}(x;\mu_k,\sigma_k^2)/p(x) are the responsibilities. Between modes, the score interpolates and can be zero at saddle points. The score field reveals the topology of the distribution: basins of attraction around modes, separatrices between them.

Example:

For a 50-50 mixture of N(−3,1)\mathcal{N}(-3, 1) and N(3,1)\mathcal{N}(3, 1), what is the score at x=0x = 0?

3 of 3
Score for Noisy Distributions

∇xtlog⁡pt(xt)=−xt−αˉt E[x0∣xt]1−αˉt\nabla_{x_t} \log p_t(x_t) = -\frac{x_t - \sqrt{\bar{\alpha}_t}\, \mathbb{E}[x_0 | x_t]}{1 - \bar{\alpha}_t}

At noise level tt the score relates directly to the conditional expectation of the clean data given the noisy observation. Because xt=αˉt x0+1−αˉt ϵx_t = \sqrt{\bar{\alpha}_t}\, x_0 + \sqrt{1 - \bar{\alpha}_t}\, \epsilon, the score points from xtx_t toward the posterior mean αˉt E[x0∣xt]\sqrt{\bar{\alpha}_t}\, \mathbb{E}[x_0 \mid x_t], rescaled by the noise variance 1−αˉt1 - \bar{\alpha}_t. This reveals the identity at the heart of the chapter: estimating the score is equivalent to estimating the denoised sample E[x0∣xt]\mathbb{E}[x_0 \mid x_t], the Bayesian optimal denoiser. The connection, formalized by Tweedie's formula, means a network trained simply to denoise implicitly learns the score, which is what the next topic exploits.

Mathematical Intuition

Tweedie's formula connects the score to the optimal denoiser: E[x0∣xt]=(xt+(1−αˉt)∇xtlog⁡pt(xt))/αˉt\mathbb{E}[x_0|x_t] = (x_t + (1-\bar{\alpha}_t)\nabla_{x_t} \log p_t(x_t))/\sqrt{\bar{\alpha}_t}. Rearranging gives ∇xtlog⁡pt=−(xt−αˉtE[x0∣xt])/(1−αˉt)=−E[ϵ∣xt]/1−αˉt\nabla_{x_t} \log p_t = -(x_t - \sqrt{\bar{\alpha}_t}\mathbb{E}[x_0|x_t])/(1-\bar{\alpha}_t) = -\mathbb{E}[\epsilon|x_t]/\sqrt{1-\bar{\alpha}_t}. This is the fundamental identity: the score equals the posterior-expected noise scaled by −1/1−αˉt-1/\sqrt{1-\bar{\alpha}_t}, making noise prediction equivalent to score estimation.

Example:

If αˉt=0.5\bar{\alpha}_t = 0.5 and the model predicts x^0=[2.0,−1.0]\hat{x}_0 = [2.0, -1.0] given xt=[1.5,0.3]x_t = [1.5, 0.3], what is the estimated score?

Theory Exercise

Problem:

Show that for data x0x_0 with the forward process xt=αˉt x0+1−αˉt ϵx_t = \sqrt{\bar{\alpha}_t}\, x_0 + \sqrt{1 - \bar{\alpha}_t}\, \epsilon, the score of the marginal distribution pt(xt)p_t(x_t) satisfies ∇xtlog⁡pt(xt)=−ϵ/1−αˉt\nabla_{x_t} \log p_t(x_t) = -\epsilon / \sqrt{1 - \bar{\alpha}_t} in expectation over x0x_0 given xtx_t, where ϵ\epsilon is the noise used to generate xtx_t.

Hints:
  • Start from $q(x_t | x_0) = \mathcal{N}(x_t; \sqrt{\bar{\alpha}_t}\, x_0, (1 - \bar{\alpha}_t) I)$
  • The score of a Gaussian $\mathcal{N}(\mu, \sigma^2 I)$ is $-(x - \mu)/\sigma^2$
  • Use Tweedie's formula: $\mathbb{E}[x_0 | x_t] = (x_t + (1 - \bar{\alpha}_t) \nabla_{x_t} \log p_t(x_t)) / \sqrt{\bar{\alpha}_t}$