Once we have the score function, we generate samples using Langevin MCMC:
Derivation: This comes from the Langevin SDE:
dx=∇xlogp(x)dt+2dW
where dW is a Wiener process. Discretizing with step size α:
xt+1=xt+α∇xlogp(xt)+2αϵ
Why the 2α noise term? It's the discretization of the diffusion term 2dW. The variance of dW over time dt is dt, so over step α it's 2α.
Annealing schedule: Start at σ1 (coarse), progressively decrease to σL (fine). This ensures:
Derivation: Given xt=αtx0+σtϵ, the conditional distribution is:
q(xt∣x0)=N(xt;αtx0,σt2I)
The score is:
∇xtlogq(xt∣x0)=−σt2xt−αtx0=−σt2σtϵ=−σtϵ
Therefore, learning to predict ϵ is equivalent to learning the score sθ(xt,t)≈−ϵ/σt.
Recall Explain to a 12-year-old
Imagine you're lost in the mountains in thick fog. You can't see the valley where you need to go, but you have a magic compass that always points downhill.
Score-based models are like that compass. Instead of trying to memorize the exact shape of every mountain (which would be impossible), we learn a "which way is down" function everywhere. Then to get to the valley (generate realistic data), we just start anywhere random and follow the compass downhill, taking small steps.
The trick is that we learn this compass by playing a game: we take real valley locations, throw them randomly up the mountain (add noise), then train our compass to point back toward where they came from. By doing this thousands of times at different heights (noise levels), our compass learns the right direction everywhere.
Diffusion Models: Score-based models are the continuous-time limit of discrete diffusion
VAE: Both learn latent structures, but scores model p(x) directly vs. encoder-decoder
GAN: Both generate samples, but scores use gradients vs. adversarial training
Energy-Based Models: Score is the gradient of the energy function E(x)=−logp(x)
Langevin Dynamics: The MCMC sampling procedure used for generation
Stochastic Differential Equations: Modern formulation treats diffusion as reverse-time SDE
#flashcards/ai-ml
What is the score function in score-based generative models? :: The gradient of the log-probability: s(x)=∇xlogp(x). It points in the direction of increasing probability density.
Why do we model the score instead of the density directly?
(1) The intractable normalization constant Z in p(x)=p~(x)/Z cancels out when taking the gradient of log p. (2) Scores are often easier to estimate in high dimensions.
What is the key insight of denoising score matching?
Add Gaussian noise x~=x+σϵ to data. The score of the noised distribution is ∇x~logq(x~∣x)=−ϵ/σ, which we can compute directly and use as training target.
Write the denoising score matching objective :: J(θ)=Ex,ϵ[21∥sθ(x+σϵ)+ϵ/σ∥2] where ϵ∼N(0,I).
Why do we use multiple noise scales in score-based models?
(1) Large σ ensures coverage of the entire space. (2) Small σ captures fine data details. (3) Intermediate scales bridge the gap, avoiding mode collapse and poor mixing.
What is annealed Langevin dynamics?
An MCMC sampling procedure that starts at high noise σ1 and progressively decreases to low noise σL, at each level running: xt+1=xt+αsθ(xt,σ)+2αzt where zt∼N(0,I).
Why weight the score matching loss by σ2?
Without weighting, small σ (large scores) dominate the gradient. Weighting by σ2 makes the loss scale-invariant and balances learning across all noise levels.
How are score-based models related to diffusion models?
In diffusion, xt=αtx0+σtϵ. The score is ∇logp(xt)=−ϵ/σt. So predicting noise ϵ (diffusion objective) is equivalent to predicting the score (up to a scale factor).
What is the Fisher divergence minimized in score matching?
Epdata[∥sθ(x)−∇xlogpdata(x)∥2]. It measures the squared difference between the model score and the true score, averaged over the data distribution.
Why does the 2α noise term appear in Langevin dynamics?
It comes from discretizing the Langevin SDE dx=∇logp(x)dt+2dW. The diffusion term 2dW has variance 2dt over time step dt, so over discrete step α it becomes 2α.
Chalo, ise simple tarike se samajhte hain. Normally generative models mein hum p(x) yaani exact probability density seekhne ki koshish karte hain, lekin ye high dimensions mein bahut mushkil hota hai, kyunki usme ek normalizing constant Z aa jaata hai jise calculate karna almost impossible hai. Score-based models ka jugaad ye hai ki hum density ke bajaye uska score function seekhte hain, matlab ∇xlogp(x). Ise aise socho jaise pahaad par khade ho aur tumhe har jagah ki exact height nahi pata, par tumhe ye pata hai ki "upar" kis direction mein hai. Bas isi slope ko follow karte hue tum random noise se shuru karke dheere-dheere realistic data tak pahunch sakte ho.
Ab magic ye hai — jab tum logp(x) ka gradient lete ho, to woh painful normalizing constant Z apne aap gayab ho jaata hai, kyunki Z ka x se koi lena-dena nahi hota. Isliye hume kabhi Z calculate karne ki zaroorat hi nahi padti, jo ki ek badi jeet hai. Lekin ek problem hai: true score to hume pata hi nahi hai, kyunki wahi to seekhna hai. Iska solution hai denoising score matching — hum data mein thoda Gaussian noise daalte hain aur network ko sikhaate hain ki us noise ko kaise hataana hai. Gaussian ke liye score ka formula seedha −ϵ/σ nikalta hai, to network basically noise predict karna seekh jaata hai aur isi process mein woh score function bhi seekh leta hai.
Ye baat isliye important hai kyunki real-world data usually high-dimensional space mein ek chhoti si "manifold" par hota hai, aur ek hi noise level se poori distribution cover nahi hoti. Isliye hum multiple noise levels use karte hain — bade σ se poora space cover hota hai aur chhote σ se data ke paas ki fine details aati hain. Yahi core idea aage jaake diffusion models ka foundation banta hai, jo aaj Stable Diffusion aur DALL-E jaise powerful image generators chalate hain. To ye topic samajhna future ke advanced generative AI ke liye ekdum zaroori hai.