FoundationsChecking saved investigationReading browser-local route memory before showing a continuation.

Foundation Lab

Score Matching & Score-Based Generative Models

Score functions are the mathematical foundation of diffusion models—the denoiser learns the score at each noise level

Concept 36 of 100Generative ModelsPhase 4
#36Score MatchingGenerative Models
key equations(x) = \nabla_x \log p(x)

Selected Foundation Object

Keep the equation fixed; move through the evidence.

Concept 36 of 100Score MatchingGenerative Models / Phase 4: Generative modeling families
Current question

The score is a vector field pointing "uphill" toward higher density—sampling follows this flow backward from noise

s(x) = \nabla_x \log p(x)
PredictionCommit before the demo.

Ask what should change when the equation is manipulated, then let the visualization test that expectation.

EvidenceCompare local witness and source.

Use the runnable panel, the key equation, and canonical papers as separate forms of evidence for the same object.

InvariantName what survives notation changes.

The useful learning product is the reusable mechanism you can carry into another model, paper, or engineering tradeoff.

Next moveContinue in the newer notebook.

This atlas page keeps the working demo; the domain notebook carries the fuller Intuition -> Math -> Code -> Demo sequence.

Why It Matters for Modern Models

  • Score functions are the mathematical foundation of diffusion models—the denoiser learns the score at each noise level
  • Explains why diffusion training is "just regression": predict noise ε, which equals -σ × score
  • Unifies VAEs, diffusion, and energy-based models through the lens of learning ∇log p(x)

What Tutorials Skip

What is still poorly explained in textbooks and papers:

  • The score is a vector field pointing "uphill" toward higher density—sampling follows this flow backward from noise
  • Why denoising works: optimal denoiser predicts E[x|x̃], and its gradient w.r.t. x̃ gives the score
  • Score matching avoids computing intractable partition functions—you only need gradients, not absolute probabilities

Interactive Visualization

Core Math (Optional Deep Dive)

If you want intuition first, start with the key equation and the visualization. Come back here for the full walkthrough.

Key Equation
s(x)=xlogp(x)s(x) = \nabla_x \log p(x)

The score function is the gradient of log-density:

s(x)=xlogp(x)s(x) = \nabla_x \log p(x)

Score matching learns sθ(x)xlogpdata(x)s_\theta(x) \approx \nabla_x \log p_{\text{data}}(x) without knowing the normalizing constant:

LSM=Epdata[12sθ(x)2+tr(xsθ(x))]\mathcal{L}_{SM} = \mathbb{E}_{p_{\text{data}}}\left[ \frac{1}{2}\|s_\theta(x)\|^2 + \text{tr}(\nabla_x s_\theta(x)) \right]

Denoising score matching (practical form):

LDSM=Ex,x~[sθ(x~)x~logq(x~x)2]\mathcal{L}_{DSM} = \mathbb{E}_{x, \tilde{x}}\left[ \|s_\theta(\tilde{x}) - \nabla_{\tilde{x}} \log q(\tilde{x}|x)\|^2 \right]

For Gaussian noise x~=x+σϵ\tilde{x} = x + \sigma\epsilon, the optimal score is ϵ/σ-\epsilon/\sigma.

Canonical Papers

Estimation of Non-Normalized Statistical Models by Score Matching

Hyvärinen2005JMLR
Read paper →

Generative Modeling by Estimating Gradients of the Data Distribution

Song & Ermon2019NeurIPS
Read paper →

Connections

Next Moves

Choose the next question to carry this object forward.