A visual exploration of flow matching
Draw one straight line from noise to a data point. Average those lines. Follow the average, and noise becomes structure.
The probability path
A line you can draw, a field you can learn
Pairing a noise sample with a data sample gives a path so simple its velocity is a constant. The field we actually learn is what those paths look like on average—and it is the one that transports the whole distribution.
- conditional
- marginal
- sample
Click inside the frame — in Sketch your own it places data in every tab; otherwise it promotes a pair in Path and re-aims the field in Conditional.
Pick a pair
Noise in, data out, straight through
Choose a noise sample and a data sample and simply interpolate between them. The resulting conditional path is Gaussian at every time, and its velocity does not depend on where you are along it.
The bold pair is one draw of (x0, x1); the faint ones are others. Along a dashed line the orange velocity is the same vector at every time.
Condition on one sample
A field that knows the answer
Fix the endpoint and the path defines a velocity field everywhere, not just on the line you drew. It transports the whole Gaussian onto that single data point—useful as a regression target, useless as a generator.
The dashed circle is the conditional Gaussian at the current time. Click any data point to condition on it instead.
Average over the data
The field that generates
Averaging the conditional fields under the posterior over endpoints gives the marginal field. It is the one that carries the noise density to the data density—and unlike the conditional field, it never needs to know which data point you were aiming at.
Blue arrows are the marginal field. Early on it points at the mean of the data; near t = 1 it splits and commits to a mode.
Generate
Sampling is solving an ODE
Draw noise, follow the marginal field to t = 1, and stop. No pairing, no score, no noise injected along the way—just an initial value problem. Because the paths are nearly straight, a handful of Euler steps already lands on the data.
Note what changed since chapter 01: the straight lines there cross each other constantly, because each is drawn for its own pair. These trajectories cannot—two solutions of the same ODE never occupy one point at one time. Traces that appear to meet on the page do so at different moments, with the time axis projected away.
Drop the step count to 2 or 3 and watch where it starts to hurt: the cost is paid at the moment the field splits between modes.
The training trick
Regress on the line, get the average for free
The marginal field is an intractable integral, so nobody regresses on it. Regressing on the single conditional vector instead works because least squares returns a conditional expectation—and that expectation is the marginal field.
Two losses, one gradient
The target you cannot compute
The flow matching loss needs ut(x); the conditional loss needs only the vector between a sampled pair. Expanding both squares shows they differ by a term that does not contain θ, so their gradients agree exactly.
What separates the two is the spread of the orange dots around the cross—the variance of the conditional target at this x. It is irreducible noise in the regression, and it is constant in θ:
Right panel: every orange dot is one conditional target, sized by its posterior weight. The loss is a quadratic bowl whose minimiser is their weighted mean.
The application
Two dimensions, or a hundred and ninety-six
Nothing above cared that the data lived in a plane. Treat a 14 × 14 image as one point in ℝ196, keep the same path and the same field, and the ODE turns static into digits—conditioned on a class, with a step budget you choose.
Click any tile to follow that sample in the filmstrip.
Same recipe, bigger vector
Static, resolved
Each tile is a single point moving through pixel space. At t = 0 it is Gaussian noise; the field pulls it toward the data manifold, and the posterior over which image it is heading for sharpens as time runs out. Conditioning simply restricts that posterior to one class.
Drop the budget to one or two steps and the tiles come out blurred: a single Euler step lands on the average of the images still in contention. More steps let the field commit before you stop.
Honest caveat: with 50 stored images and the exact field, this memorises—each sample converges to a training image. A learned vθ is a smooth approximation, and that smoothing is where novel samples come from.
Real image models replace the 50 stored pictures with a network trained by exactly the loss in chapter 02, and the same construction now drives text-to-image and video systems as well as robot policies, where a chunk of future actions plays the role of the image — see Esser et al., Scaling Rectified Flow Transformers (2024) and Black et al., π₀ (2024).