AI State of the Art
Fundamentals/Deep Learning: Fundamental Architectures/31 min
Section 28

Score-based Generative Models and Flow Matching

Listen as a podcast β†’

A story: finding your way through the fog

Imagine you're lost in thick fog. You can't see more than 10 feet ahead. But someone at the top of a tower shouts to you, every second: "Go more to the left! Now go up a bit! Turn right!" By following these directional cues, you eventually make it out of the fog and reach the exit of the maze.

This is exactly what score-based generative models do with data. Except instead of a maze, it's a complex, very high-dimensional space, and instead of a person, it's a trained neural network shouting the directions.

The score is that shout: an arrow pointing toward where the real data is denser. Mathematically, it's the gradient (the slope) of the probability density:

s(x)=βˆ‡xlog⁑p(x)s(x) = \nabla_x \log p(x)

Symbol by symbol: xx is a point in space, here an image; p(x)p(x) is the probability density at that point, i.e., how thickly real data crowds around it; log⁑\log is the logarithm; βˆ‡x\nabla_x (the upside-down triangle, read "nabla") is the gradient with respect to xx: the arrow pointing in the direction where whatever follows increases fastest; s(x)s(x) is the score, hence that arrow. In one sentence: "in which direction does the density of real data increase the most?"

Why the score and not the density directly?

Modeling the density p(x)p(x) directly is a mathematical nightmare. A network can easily output a positive number for each image, but for those numbers to form a genuine probability distribution, their total over all possible images has to come to exactly 1. So you divide by a constant Z=∫pβˆ—(x) dxZ = \int p^*(x)\,dx, where ∫\int is the integral (the continuous sum over all of space) and pβˆ—p^* the raw unnormalized score. Computing that ZZ is out of reach in high dimensions: you would have to sweep every conceivable image.

The score sidesteps the problem, because the gradient of the logarithm makes the constant vanish: βˆ‡xlog⁑pβˆ—(x)Z=βˆ‡xlog⁑pβˆ—(x)\nabla_x \log \frac{p^*(x)}{Z} = \nabla_x \log p^*(x), since the logarithm turns division into subtraction and the derivative of a constant is zero. It's like asking "which direction should I go?" instead of "what's the exact probability here?" Much easier to learn.

Score matching: learning from blurry photos

The idea is clever: train the network not directly on clear images, but on versions noised at different blur levels.

Take a beautiful photo (real data). Now add random noise. A little. Then a lot. Then a huge amount. You get increasingly blurry images.

For each blurry image, the score (the direction to follow) is easy to compute: it's simply "how many pixels would you need to shift to get back to the original image?", divided by the amount of noise.

Now: train the network on all these blurry cases. "Here's a blurry image. Tell me which direction to move the pixels to make it less blurry."

  1. Noise the data: x~=x+Ο΅\tilde{x} = x + \epsilon
  2. The score is simple: s=βˆ’(x~βˆ’x)/Οƒ2s = -(\tilde{x} - x) / \sigma^2
  3. Train the network: L=βˆ₯sΞΈ(x~)βˆ’srealβˆ₯2L = \| s_\theta(\tilde{x}) - s_{\text{real}} \|^2

Symbol by symbol across those three lines: xx is the clean image; x~\tilde{x} ("x tilde") the dirtied one; Ο΅\epsilon (epsilon) the noise added; Οƒ\sigma (sigma) the standard deviation of that noise, i.e., its strength, and Οƒ2\sigma^2 its square; ss the exact score, which we know here because we made the noise ourselves, hence the minus sign: the useful direction is the one that leads back from x~\tilde{x} to xx; sΞΈs_\theta the score predicted by the network, where the subscript ΞΈ\theta (theta) stands, by convention, for the network's learned weights, the only thing training modifies, everything else being drawn at random or computed; LL the loss, the squared gap between predicted and exact score.

The trick: the network learns to remove noise without ever seeing a fully clear image. Just the general pattern of "which direction to clean."

Multi-scale: from fog to detail

Real data is never uniformly distributed. With little noise, the network learns fine details (eyes in an image). With a lot of noise, it learns global shapes (is this a face?). The network learns both simultaneously.

Generation: following the arrow from fog to clarity

After training, how do you generate an image? It's Langevin dynamics:

  1. Start with pure noise (a random image, total chaos)
  2. At each step, ask the network: "Which way should I go to get closer to real data?"
  3. Move a little bit in that direction
  4. Add a tiny bit of random noise for exploration (this noise prevents getting stuck in a local minimum)
  5. Repeat hundreds of times
xt+1=xt+Ξ·2 sΞΈ(xt)+η z,z∼N(0,I)x_{t+1} = x_t + \frac{\eta}{2} \, s_\theta(x_t) + \sqrt{\eta} \, z, \quad z \sim \mathcal{N}(0, I)

Symbol by symbol: xtx_t is the image at iteration tt, xt+1x_{t+1} the next one; sΞΈ(xt)s_\theta(x_t) is the direction the network points in at that point; Ξ·\eta (the Greek letter eta) is the step size, a hand-set dial: too large and you leap over the interesting regions, too small and you never arrive; zz is noise drawn at random, added to keep exploring; Ξ·\sqrt{\eta} is the square root of the step size. The factor 12\frac{1}{2} on the step and the square root on the noise are not arbitrary: they come from how you chop the continuous Langevin equation into small steps, where the random part grows like the square root of elapsed time rather than like time itself. It is the same phenomenon as a random walk, which drifts from its starting point like the square root of the number of steps.

In one sentence: move a little in the direction the network indicates, then add a small random jolt, and repeat. It's like walking through fog asking for directions at every step: you never go in a straight line, but eventually you emerge toward a real data point.

Three panels linked by arrows. On the left, data points in two clusters with a few face thumbnails. In the middle, a field of small black arrows spread over the whole plane, pointing toward the dense regions, labelled Scores. On the right, a grid of generated faces labelled New samples. The arrows between panels are labelled score matching and Langevin dynamics.
The middle panel is the fog from the opening story: each little arrow is the score at one point in space, that is, the direction in which the density of real data increases. On the left, what the network sees during training. On the right, what you get by following those arrows step by step starting from pure noise.Source : Yang Song, blog post Generative Modeling by Estimating Gradients of the Data Distribution, via The AI Summer

In practice, for images (which have millions of pixels), you start with lots of noise and gradually reduce it, this is "noise annealing." First, the network learns rough shapes. Then details. Then fine textures.

Technical corner: stochastic differential equations

Abbreviated SDE: equations describing how a quantity evolves continuously, like ordinary differential equations, but with an added randomness term, "stochastic" simply meaning "involving chance."

In 2021, Song and his co-authors showed something striking: the main families of noise-based generative models, DDPM (Denoising Diffusion Probabilistic Models, the diffusion models of the previous lesson) and the score estimation of this page, are special cases of one and the same framework, that of SDEs. Mind the exact scope of the claim: it does not hold for all generative models (neither a GAN, Generative Adversarial Network, see GANs nor an autoregressive language model fits this frame), but it does for the whole family that works by progressively adding and then removing noise.

In simple terms: how do you progressively transform one thing into another by adding, then removing, noise?

Forward:dx=f(x,t) dt+g(t) dW\text{Forward:} \quad dx = f(x, t)\,dt + g(t)\,dW Backward:dx=[f(x,t)βˆ’g(t)2β€‰βˆ‡xlog⁑pt(x)]dt+g(t) dWΛ‰\text{Backward:} \quad dx = \left[f(x,t) - g(t)^2 \, \nabla_x \log p_t(x)\right] dt + g(t)\,d\bar{W}

Symbol by symbol: dxdx is the tiny change in the image over the instant dtdt, the dd notation signals "an infinitesimally small amount of"; tt is time, running from 0 (clean data) to 1 (pure noise); f(x,t)f(x,t) is the drift, the predictable part of the motion, the part that pulls the system in a given direction; g(t)g(t) sets the noise strength at instant tt; dWdW is the noise itself, called Brownian after the erratic motion of pollen grains in water observed by Robert Brown; dWΛ‰d\bar{W} is the same noise traversed in reverse time; βˆ‡xlog⁑pt(x)\nabla_x \log p_t(x) is the score, exactly the same quantity as at the top of this page, but measured on the distribution as it stands at instant tt.

One sentence for each: forward, you start from real data and let it drift while shaking it, until nothing is recognizable; backward, you start from pure noise and travel back upstream, the score serving as your compass. Notice that the "backward" line is the "forward" line minus a term containing the score: that is the only missing ingredient, and it is the one the network learns.

The value of this unification is thoroughly practical: an improvement found in one setting (a better noise schedule, a faster solver) transfers immediately to the other.

Two-part diagram. On the left, Forward SDE: starting from a two-humped data distribution, noisy red trajectories and smooth white curves spread out into a single Gaussian labelled Prior. On the right, Reverse SDE: the same process run the other way, from the Gaussian back to the two-humped distribution. Both differential equations are written above, the right-hand one containing the gradient of log p_t term.
The same picture read left to right (data is destroyed by drowning it in noise) and right to left (data is rebuilt from noise). The red traces are the stochastic SDE trajectories, the white curves the equivalent deterministic version. The only missing ingredient for travelling the right-hand half is the score, which the network learns.Source : Song et al. 2021 paper (figure 2), via The AI Summer
Two papers not to confuse

The score literature rests on two distinct articles by the same authors, and they get mixed up constantly:

  • Song and Ermon, 2019, Generative Modeling by Estimating Gradients of the Data Distribution: this is the one that introduces learning the score at multiple noise levels and generating by Langevin dynamics. That title is also the title of the blog post the illustration above comes from.
  • Song et al., 2021, Score-Based Generative Modeling through Stochastic Differential Equations: this is the one that brings the SDE unification described in this section. Its abstract reports, on CIFAR-10 in unconditional generation, an Inception Score of 9.89 and an FID of 2.20 (recall: IS reads upward, FID downward).

It was the second that unlocked what followed: once the common framework was in place, every advance in numerical solvers benefited all the variants at once.

Score-Based Generative Modeling through Stochastic Differential Equations (Song et al., 2021)

Flow matching: the modern and simple approach

After complex SDEs, a simpler idea emerged: forget stochastic equations, just think about direct paths.

The idea: take noise. Take a real data point. Now imagine a straight line connecting them. Ask the network: "At each point along this line, what's the velocity vector to move toward the real data?"

xt=(1βˆ’t)β‹…z+tβ‹…x1,z∼N(0,I)x_t = (1 - t) \cdot z + t \cdot x_1, \quad z \sim \mathcal{N}(0, I) v=x1βˆ’zv = x_1 - z L=βˆ₯vΞΈ(xt,t)βˆ’vβˆ₯2L = \| v_\theta(x_t, t) - v \|^2

Symbol by symbol: zz is the starting point, noise drawn at random; x1x_1 is the destination, a real image from the dataset; tt is the position along the path, from 0 (you are on the noise) to 1 (you are on the image); xtx_t is the point of the path at that position, obtained by blending the two ends in proportions (1βˆ’t)(1-t) and tt; vv is the velocity to follow, here simply the arrow from noise to image, the same everywhere since the path is a straight line; vΞΈv_\theta is the velocity predicted by the network, whose ΞΈ\theta stands for the learned weights; LL is the loss, the squared gap between predicted and true velocity.

In one sentence: place yourself anywhere between a noise sample and an image, and teach the network to point at the image. Incredibly simple. No noise at each step, no noise schedule to tune. Just: "predict the direction of movement."

The results are excellent, and this is indeed the approach recent models have adopted, Stable Diffusion 3 is trained this way. Why?

  1. Simple to implement: the core of the algorithm fits in a few lines of code
  2. Easy to train: no more noise schedule to tune, which was one of diffusion's most delicate settings
  3. Shorter generation: a few dozen steps instead of the thousand of original diffusion
The beauty of flow matching

It's the kind of idea you look at in hindsight and think "why didn't anyone think of this before?" A network learns a velocity field: at every point in space and every instant, an arrow saying where to go. That's all. No random jolt, no noise strength to wind down. Just geometry, and a kinship with the theory of optimal transport, the branch of mathematics studying how to move a mass from one configuration to another at least cost, the very one that gave GANs their Wasserstein distance.

Rectified flows: the shortest paths possible

Here's a natural question: rather than curved, winding paths from noise to data, why not have perfectly straight paths?

If the paths are straight, you can generate in a single step: one giant step in the right direction. The arithmetic is immediate, one step instead of a hundred, so a hundred times fewer calls to the network.

Why aren't the paths straight to begin with, given that we defined the training paths as straight lines? Because each noise sample is paired with a random image, and those straight lines cross. At the crossings the network receives two contradictory instructions; it therefore learns the average, and that average traces out curves.

Rectified flows use an iterative trick to straighten all this out:

  1. Train normal flow matching
  2. Generate many trajectories with this model
  3. Analyze them, notice they're curved
  4. Retrain on these trajectories to make them straighter
  5. Repeat, the trajectories become straighter with each iteration
Four side-by-side panels showing trajectories between a cluster of purple points on the left and a cluster of red points on the right. Panel a, linear interpolation with random coupling: the paths cross in an X. Panel b, learned rectified flow: the paths no longer cross but remain clearly curved. Panels c and d, after rectification: the paths are almost straight horizontal lines.
The whole idea of rectification in one picture. At the start (a), noise and data are paired at random and the paths cross; the network can then only learn curved trajectories (b), which force you to take many small steps. After re-pairing and retraining (c, d), the paths are nearly straight: a single giant step takes you from noise to data.Source : Illustration by Hunter Heidenreich, after the Rectified Flow paper (Liu et al.)

Result after a few iterations: generation in very few steps, down to a single one in favourable cases. You start from pure noise, take one large step in the direction the network has learned, and you get an image. This is the direction the most recent generative models are heading; straightening does cost a slight quality drop, though, compared with leaving the same model to run over several steps.

Practical comparison

The step count is the objective part of this comparison; the "quality" column is a qualitative judgement from the literature, not a measurement, FID figures do not compare across image sets.

ApproachTrainingSteps to generateReported quality
DDPMSimple, robustSlow: on the order of a thousandExcellent
Score via SDERich theoretical frameFlexible: from ten to a thousandExcellent
Flow matchingVery simpleFast: a few dozenExcellent
Rectified flowsSimple, then rectificationVery fast: 1 to about tenSlightly behind
Where does this stand in 2026?

Flow matching has established itself as the default training framework for new image generators: Stable Diffusion 3 is the best-documented public case. It's the formalism you will meet most often: simple, efficient, theoretically clean. SDEs and DDPM remain indispensable for understanding where all this came from and for reading the 2020-2022 literature, but they are no longer the recipes you reach for first.

Why this matters

DALL-E, Midjourney, Stable Diffusion: all rest on these ideas. Understanding how noise gets turned into a realistic image means understanding the heart of today's image generation.

Key takeaways

  1. The score = the direction toward real data, i.e., the gradient of the log density
  2. Score matching = training on noisy images to learn that direction without ever having to compute the normalization constant
  3. Langevin dynamics = repeatedly following the score direction, with a small random jolt at each step, to generate new data
  4. SDEs = the mathematical framework that brings DDPM and score estimation under one formalism, not the whole of generative modelling
  5. Flow matching = today's approach, which replaces step-by-step noising with direct paths between noise and data
  6. Rectified flows = those paths made nearly straight, so generation takes one step to a handful
Check your understanding0 / 5

1. Why learn the score (the direction toward real data) rather than the probability density itself?

2. In Langevin dynamics, why add a small random jolt at each step, on top of the direction the network indicates?

3. What exactly does the SDE unification of Song et al. in 2021 show?

4. In flow matching, the training paths are defined as straight lines between a noise sample and an image. Why does the trained model nonetheless produce curved trajectories?

5. In 2026, what is the default training framework for new image generators?