Denoising and Score-Based Models
Imagine you want to generate realistic images. Instead of learning the probability of each image directly, you learn something subtler. You learn which direction in pixel space makes an image more likely. This direction field, called the score, is the gradient of the log-density of the data distribution. If you had this field everywhere, you could start from random noise. You would simply "walk uphill" toward regions of high probability. This arrives at realistic samples. This is the central idea behind score-based generative modeling. It is a framework that unifies denoising autoencoders, Langevin dynamics, and Diffusion Models: Forward and Reverse Processes into one coherent mathematical story. The practical obstacle is that the true score of real data is unknown. The density itself is intractable to normalize. Computing it directly would require an impossible integral over all of image space. Score-based models sidestep this by learning to estimate the score using only samples. They do this via an objective called score matching. This objective remarkably never needs the normalizing constant at all. A key insight, due to Vincent's denoising score matching, shows something important. Training a network to denoise noisy data is mathematically equivalent to training it to estimate the score of the noised distribution. This connects an easy, well-posed regression problem — predict the noise that was added — to the deep theoretical object of a score field. This equivalence matters enormously in practice. Modern diffusion models (DDPM, score-based SDE models, Stable Diffusion's underlying samplers) are, at their core, networks. They are trained with a denoising objective that implicitly estimates a score function at many noise scales. Sampling then proceeds via Langevin dynamics or related stochastic differential equation solvers. These solvers use the learned score to iteratively refine a noisy sample into a clean one. Understanding score matching and its denoising equivalent demystifies something important. It explains why "predict the noise" training produces samplers capable of generating photorealistic images, audio, and molecules. This article builds the theory from the ground up. It covers what a score is, and why matching it via denoising works. It explains how Langevin sampling turns a score field into a generator. It also shows how multiple noise scales make the whole scheme robust. We give exact pseudocode for training and sampling. We include a worked numerical trace on a small example. We connect the ideas to the wider diffusion-model literature.
- The score is , a vector field pointing toward higher data density, learned instead of the intractable density itself.
- Score matching trains a network to approximate the score without ever computing the normalizing constant of .
- Denoising score matching shows that predicting the noise added to a corrupted sample is equivalent to estimating the score of the noised distribution.
- Langevin dynamics uses the learned score plus injected noise to sample from the data distribution by iterative stochastic gradient ascent on log-density.
- Multiple noise scales (annealed Langevin dynamics) fix the low-density-region problem, letting the sampler traverse from pure noise to sharp data.
- This framework is mathematically the continuous-time/score-based view underlying denoising diffusion probabilistic models (DDPMs).
Learning to denoise data at many noise levels is secretly learning the gradient field of the log-density — and following that gradient with injected noise (Langevin dynamics) generates new samples.
The idea
Let be an unknown data distribution over (e.g. natural images flattened into vectors). Its score function is defined as
This is a vector field: at every point in space it tells you the direction of steepest ascent of the log-density. Crucially, the score does not depend on the normalizing constant of an unnormalized density , since (the constant's gradient is zero). This is what makes the score attractive: many models can output an unnormalized energy or likelihood easily, but normalizing it (computing ) is intractable in high dimensions. Estimating the score avoids that computation entirely.
Score matching is the general name for training a parametric vector field to approximate , typically by minimizing the expected squared error
The apparent problem is that the right-hand side needs the true score, which we don't have. Hyvärinen's original score matching (2005) showed this objective is equal, up to a constant, to a quantity involving only and its Jacobian trace — computable from samples alone, no density evaluation needed. However, that formulation requires computing , which is expensive for large neural networks (it costs backward passes in the naive case).
Denoising score matching (DSM), introduced by Vincent (2011), gives a far cheaper alternative. Instead of matching the score of the clean data distribution directly, DSM perturbs each data point with Gaussian noise, , , and matches the score of the noised distribution . The remarkable fact — proved below — is that this noised score has a closed form conditional on , turning score estimation into a simple regression: predict the (scaled) noise from the corrupted sample.
How it works
Step 1 — The denoising score matching identity. For Gaussian corruption , the conditional density is , so
Vincent's theorem states that minimizing
has the exact same minimizer as matching the true marginal score of the noised data distribution. In other words, training a network to predict the (negative, scaled) noise from a noisy sample is identical, in expectation over data, to training it to output . This is the bridge between "denoising autoencoders" and "score estimators."
Step 2 — Reparametrize as noise prediction. Networks are usually trained to predict directly via , related to the score by
The training loss becomes the familiar denoising objective
which is exactly the loss used to train DDPM-style diffusion models — confirming that "predict the noise" training is score matching in disguise.
Step 3 — Multiple noise scales. A single is not enough: at low noise, the score is only accurate near the (thin) data manifold, so a sampler starting from random noise (a low-density region) gets an unreliable gradient signal. The fix, due to Song & Ermon (2019), is to train one network conditioned on a range of noise levels (large to small), giving a noise-conditional score network (NCSN) . The training objective sums weighted DSM losses across levels:
(the weighting balances the loss scale across noise levels, since raw DSM loss magnitudes scale like ).
Step 4 — Langevin dynamics for sampling. Given a good score estimate, sampling from uses Langevin dynamics: starting from (e.g. uniform or Gaussian noise), iterate
for small step size . As and , the distribution of converges to regardless of the starting point — this is a classical result from stochastic differential equations (Langevin dynamics is the Euler–Maruyama discretization of a diffusion process whose stationary distribution is exactly ).
Step 5 — Annealed Langevin dynamics. To handle the multiple noise scales, sampling starts with a large (score is smooth and reliable everywhere, since noise has spread density over the whole space) and gradually anneals down to (score is sharp, matching the true data score), running a few Langevin steps at each level and using the previous level's output as the next level's initialization. ```text ALGORITHM: Train Noise-Conditional Score Network Input: dataset D, noise scales sigma_1 > sigma_2 > ... > sigma_L, network s_theta Output: trained parameters theta repeat until convergence: sample minibatch {x_1, ..., x_B} from D for each x_b in minibatch: sample i ~ Uniform{1, ..., L} # random noise level sample epsilon ~ Normal(0, I) x_tilde = x_b + sigma_i epsilon # corrupt target = -epsilon / sigma_i # true score of noised conditional pred = s_theta(x_tilde, sigma_i) loss_b = sigma_i^2 || pred - target ||^2 # weighted DSM loss theta = theta - lr * gradient( mean(loss_b), theta ) return theta
ALGORITHM: Annealed Langevin Dynamics (Sampling) Input: trained s_theta, noise scales sigma_1 > ... > sigma_L, step size epsilon_step, steps-per-level T Output: sample x approximately from data distribution p(x) x = sample from simple prior (e.g. uniform noise) for i = 1 to L: alpha_i = epsilon_step (sigma_i / sigma_L)^2 # step size scaled per level for t = 1 to T: z = sample Normal(0, I) x = x + (alpha_i / 2) s_theta(x, sigma_i) + sqrt(alpha_i) * z return x ``` The figure below shows the overall pipeline: a clean sample is corrupted at several noise scales, a shared network learns to output the corresponding score at each scale, and annealed Langevin sampling reverses the process from noise back to data.
Complexity & correctness
Training complexity. Each training step requires one forward and backward pass of the score network per minibatch element, exactly like standard supervised regression. If the network has parameters and processes a batch of size , the cost per step is where is the cost of one forward/backward pass (dominated by the network architecture, e.g. a U-Net's convolution cost). Crucially, DSM avoids the -times-more-expensive Jacobian-trace term required by vanilla score matching — this is the entire practical reason DSM (and its noise-prediction reparametrization) became the standard training recipe rather than Hyvärinen's original objective.
Sampling complexity. Annealed Langevin dynamics runs noise levels with steps each, so generating one sample costs network evaluations, each . This is markedly more expensive than a single forward pass of a GAN or VAE decoder — the classic accuracy/speed tradeoff of iterative generative samplers, shared with diffusion models generally. Typical values are – noise levels and – steps, so total sampling steps range from the low hundreds to tens of thousands depending on the sampler and schedule.
Correctness of denoising score matching (proof sketch). We show and the marginal score-matching objective share the same minimizer. Expand the marginal objective for the noised distribution :
Expand the square; the cross term is (using ). Writing and swapping the order of integration and differentiation (justified for smooth Gaussian kernels),
Substituting back shows the cross term equals , i.e. the marginal score can be replaced by the conditional score inside the expectation, without changing the cross term. The term is unaffected by this substitution (it doesn't involve the true score at all), and the term is a constant independent of . Hence
so the two objectives have identical gradients with respect to and identical minimizers. This is the precise statement of Vincent's theorem: denoising is provably equivalent to score matching, not merely a heuristic approximation.
Correctness of Langevin sampling. The stochastic process (a Langevin diffusion, a Wiener process) has as its unique stationary distribution — this follows from the Fokker–Planck equation: the density evolution vanishes exactly when (direct substitution, using ). The discrete-time update in the algorithm is the Euler–Maruyama discretization of this SDE; as step size and iteration count , the discretized chain's distribution converges to under mild regularity (smoothness, tail conditions on ). In practice is finite, introducing discretization bias, and mixing time can be slow when has well-separated modes — precisely the failure mode that motivates using many noise scales: at large , the noised distribution has merged, well-connected modes (since convolving with a wide Gaussian smooths out the density), making Langevin mixing fast, and progressively smaller refines the sample without needing to cross low-density valleys from scratch.
Honest tradeoffs. Score-based/diffusion samplers trade slow, iterative sampling for training stability (no adversarial min-max as in GANs) and for tractable exact-ish likelihoods via the SDE/ODE formulation. They also need careful noise-schedule design ( large enough to smooth all modes together, small enough to recover fine detail) — a schedule that is wrong in either direction visibly degrades sample quality.
Worked example
Consider a toy 1-D dataset with two clusters: is a mixture . Suppose we have (for illustration) the exact score and want to see how one Langevin step behaves at two different noise scales. At (no smoothing, i.e. the raw data score) and starting at — exactly between the two modes — the true density is nearly flat and symmetric there, so : the sampler receives almost no directional signal and must rely entirely on injected noise to randomly drift toward one mode. This is slow and can get stuck bouncing near for a long time if is small. Now consider training at a large noise scale, . The noised distribution convolves the two narrow Gaussians with a wide kernel, producing a single broad, unimodal bump centered near . Its score at is still by symmetry, but nearby, e.g. at , the score is a clear, strong restoring pull because the density is now smoothly varying (no flat plateau), giving Langevin dynamics a usable gradient everywhere. Table below traces one representative sampling run (illustrative numbers, , single Langevin step per level shown):
| Stage | Position | Estimated score | Update () | New | |
|---|---|---|---|---|---|
| Start | — | (from prior) | — | — | |
| Level 1 | (nearly flat, mild pull) | (noise-dominated) | |||
| Level 2 | (pulled toward +3 mode, now visible) | ||||
| Level 3 | (stronger pull) | ||||
| Level 4 | (sharp pull toward ) | ||||
| Level 5 | (very sharp, close to true score near mode) |
The trace illustrates the essential mechanism: at large the score field is smooth and provides a weak but non-degenerate signal that breaks the symmetric tie, nudging the sample toward one basin; as anneals down, the score sharpens and increasingly concentrates the sample exactly onto a mode (), reproducing samples indistinguishable from the true cluster at . Had we started directly at , the near-zero score at would have left the sampler with no directional cue, illustrating why annealing is not an optimization trick but a necessity for score-based sampling in multimodal or manifold-supported data (real images live on a low-dimensional manifold, an extreme version of this same low-density problem).
Common pitfalls & traps
| Pitfall | Why it happens | Consequence |
|---|---|---|
| Using a single, small noise scale | Score is only accurate near the data manifold; off-manifold points get near-zero or wildly inaccurate score estimates | Langevin chain fails to mix, samples collapse to noise or a single mode |
| Forgetting the (or ) loss weighting | Raw DSM loss scales like , so unweighted training is dominated by the smallest noise level | Large- levels are under-trained, breaking the annealing schedule |
| Confusing score with density | The score is a vector field, not a scalar; it cannot be directly compared across models or normalized like a probability | Misinterpreting relative sample likelihoods from score magnitude alone |
| Step size too large in Langevin dynamics | Euler–Maruyama discretization error grows with ; large steps overshoot narrow density modes | Samples are biased, blurry, or diverge numerically |
| Ignoring the Jacobian-swap assumption in the DSM proof | Requires to be smooth (true for Gaussian noise) — breaks for non-smooth corruptions | Naively applying DSM identity to arbitrary corruption processes gives wrong gradients |
| Treating noise-prediction MSE as exact likelihood | The training loss is a bound/surrogate related to score matching, not the exact data log-likelihood | Comparing raw MSE losses across different noise schedules as if they were likelihoods |
Pioneers & history
Score-based generative modeling sits at the confluence of statistical estimation theory, stochastic differential equations, and deep generative modeling. Aapo Hyvärinen formalized score matching as a general estimation principle for unnormalized models, sidestepping the need to compute partition functions. Pascal Vincent later proved that a simple denoising task is mathematically equivalent to matching the score of a Gaussian-smoothed data distribution, linking score matching to the older tradition of denoising autoencoders. Yang Song and Stefano Ermon then showed that combining multiple noise scales with annealed Langevin dynamics makes score-based sampling practical on high-dimensional image data, directly foreshadowing modern diffusion samplers and their SDE-based generalization.
Origins · 1 minAapo Hyvärinen and how this was discovered
Where this matters
Score-based and denoising principles are the mathematical backbone of modern diffusion generative models used in text-to-image systems (Stable Diffusion, Imagen, DALL·E 2's diffusion decoder), where the "noise prediction" U-Net is precisely a score estimator at many noise scales, as derived above. The same machinery underlies diffusion-based audio synthesis (WaveGrid, DiffWave), molecule and protein conformation generation, and video generation models. Beyond generation, score estimates are used for out-of-distribution detection (regions of low score-consistency indicate off-manifold inputs), inverse problems such as image inpainting and super-resolution (via guided Langevin sampling with a data-consistency term), and as a theoretical tool connecting energy-based models to tractable training via denoising objectives, avoiding expensive MCMC-based maximum-likelihood training. Any system that trains a neural network to "predict the noise" is, under the hood, relying on the score-matching equivalence explained here.
Ask the tutor: How does the score-SDE framework unify discrete noise-conditional score networks and DDPM's discrete-time diffusion process into one continuous-time model?
Is the score the same thing as the probability density?
No. The score is a vector field — it tells you the direction in which log-density increases fastest at each point, not the density's value. Two very different densities can have similar-looking score fields in some regions, and the score alone does not let you compute relative likelihoods of two arbitrary points without integrating the field along a path between them. This distinction is exactly why the score is easier to estimate than the density: it discards the hard-to-compute normalizing constant while retaining all the local information needed for gradient-based sampling methods like Langevin dynamics.
Why does predicting noise (as in DDPM) count as score matching?
Because of Vincent's denoising score matching identity: when data is corrupted with Gaussian noise , the conditional score of the noising kernel is exactly . Training a network to predict from with mean-squared error is, up to a constant not depending on parameters, identical to training that network's rescaled output to match the true score of the noised marginal distribution . So "predict the noise" is not a separate heuristic from score matching — it is score matching, reparametrized into a numerically convenient regression target.
Why can't we just use a single, very small noise level for training and sampling?
At small noise, the noised distribution stays close to the true data distribution, which is often concentrated on a thin, low-dimensional manifold inside a high-dimensional space (natural images, for instance). Far from that manifold, the true density is nearly zero, so the score there is either poorly defined for a finite training set or wildly inaccurate as estimated by a neural network with limited data coverage. A Langevin sampler initialized at random noise starts exactly in these low-density regions, so it needs a smooth, informative score there — which only larger noise scales provide, since convolving with a wide Gaussian spreads density over the whole space.
How is Langevin dynamics guaranteed to sample from p(x)?
Langevin dynamics discretizes the stochastic differential equation . Its stationary distribution, obtained by solving the associated Fokker–Planck equation for , is exactly : substituting into the Fokker–Planck drift-diffusion balance makes both sides vanish identically. In the limit of infinitesimally small step size and infinitely many iterations, the discretized chain converges to this stationary distribution. In practice, finite step sizes introduce a controllable bias, and slow mixing between well-separated modes is the main practical failure mode, which multi-scale annealing is designed to fix.
What is the difference between score matching and denoising score matching?
Plain score matching (Hyvärinen, 2005) trains to match the true score of the clean data distribution directly, using an objective that requires computing the trace of the network's input-output Jacobian — expensive for large networks, roughly times costlier than a normal forward/backward pass. Denoising score matching instead matches the score of a Gaussian-smoothed version of , using a conditional score that has a simple closed form (), removing the Jacobian-trace computation entirely and turning training into ordinary regression. The tradeoff is that DSM only recovers the score of the noised distribution, not the clean one — which is precisely why multiple noise scales, annealed down toward zero, are used to approximate the clean score in the small- limit.
How does this relate to diffusion models I may have already studied?
Denoising diffusion probabilistic models define a forward process that gradually adds Gaussian noise to data over many steps, and train a network to reverse it by predicting the noise at each step — exactly the denoising score matching setup described here, with replaced by a time-indexed noise schedule . The reverse sampling process in DDPMs is a discretized, time-dependent analogue of annealed Langevin dynamics. Song et al.'s score-SDE framework formally unifies both views: DDPM's discrete-time forward process and the noise-conditional score network's discrete noise levels are two discretizations of the same underlying continuous-time diffusion SDE, with the same score-matching training objective.
Can score-based models be used for tasks other than pure generation?
Yes. Because the learned score approximates , it can be used for anomaly or out-of-distribution detection (points where the score is inconsistent or the implied density is low are likely anomalies), for solving inverse problems like inpainting and super-resolution (by combining the learned score with a data-consistency gradient during Langevin sampling), and for approximate density estimation via the probability-flow ODE associated with the score SDE, which permits (approximate) likelihood computation through an instantaneous change-of-variables formula. These applications all reuse the same trained score network without retraining.