Score-Based Models and Flow Matching
Definition: Score Function and Score Matching
Score Function and Score Matching
The score function is the gradient of the log-density:
Score matching trains without knowing . Denoising score matching adds noise and learns:
Definition: Flow Matching
Flow Matching
Flow matching learns a velocity field that transports noise to data along straight paths:
Sampling: solve the ODE from to .
Flow matching is simpler to train than score-based SDEs and often requires fewer sampling steps.
Example: Flow Matching Training
Implement flow matching training for 2D data.
Solution
Implementation
for x1 in data_loader: # target data
t = torch.rand(x1.size(0), 1)
x0 = torch.randn_like(x1) # noise
xt = (1 - t) * x0 + t * x1
v_target = x1 - x0
v_pred = model(xt, t)
loss = F.mse_loss(v_pred, v_target)