03 · Learning the score

NoteDraft — Learning the score

These lecture notes are in development and may be revised. Part 1 established that a score and the forward schedule determine a sampling vector field; Part 2 extended the construction to vectors. We begin with supervised denoising: predict a clean input from its noisy version. Squared-error regression learns the posterior mean, which supplies the score through Tweedie’s formula. We first use scalars to make the conditional expectations explicit, then state the vector formulas.

NotePrimary reference and learning objective

The primary reference is Song et al., Score-Based Generative Modeling through Stochastic Differential Equations, ICLR 2021, arXiv:2011.13456v2. Use Section 3.3, Eq. (7), for training; Section 4.3, Eq. (13), for the probability-flow ODE; and Appendix B for the linear VP schedule and its Gaussian transition law. The paper’s reverse SDE is Eq. (6), a different sampling dynamics from Eq. (13).

Complementary references:

Sampling is the goal. The sampler needs a score to evaluate its vector field. To learn that score, first consider an ordinary supervised problem: generate clean/noisy pairs and predict the clean value from the noisy input. Squared-error regression learns the posterior mean clean value. Tweedie’s formula converts this mean into the marginal score. Conditional-score and noise prediction are alternative parameterizations of this learning problem, with different time weightings unless the losses are adjusted. Explicit Euler integration with decreasing time then generates approximate data samples. Training and sampling must use the same schedule and time convention.

1. The forward process, SDE, and noise schedule

Generation requires evaluating a vector field at the current sample and time. For VP diffusion, the probability-flow field in one dimension is

\[v(x,t)=-\frac{\beta(t)}2[x+s_t(x)],\qquad s_t(x)=\frac{d}{dx}\log p_t(x).\]

The schedule is chosen by us; the marginal score is unknown. Our dataset contains observations \(X_0\sim p_{\mathrm{data}}\), not values of \(p_t\) or its derivative. We can construct a denoising regression problem from those observations. We will first identify its posterior-mean solution, then show how it determines the required score.

The forward process and its SDE

Choose a nonnegative rate schedule \(\beta(t)\) on \(0\le t\le1\). The forward VP process contracts positions and adds Gaussian noise. Its SDE is

\[\boxed{dX_t=-\frac{\beta(t)}2X_t\,dt+\sqrt{\beta(t)}\,dW_t.}\]

Define the cumulative signal amplitude by

\[\boxed{\alpha_t=\exp\!\left[-\frac12\int_0^t\beta(u)\,du\right], \qquad\alpha_0=1.}\]

The corresponding conditional law can be sampled directly at any selected positive time:

\[\boxed{X_t\mid X_0=x_0\sim\mathcal N(\alpha_t x_0,1-\alpha_t^2), \qquad X_t=\alpha_tX_0+\sqrt{1-\alpha_t^2}\,\varepsilon,}\]

where \(\varepsilon\sim\mathcal N(0,1)\) is independent of \(X_0\). This formula generates a training observation at one selected time; it does not specify an SDE trajectory by reusing the same noise at every time.

The rate and accumulated amplitude describe the same schedule:

\[\boxed{\alpha_t'=-\frac{\beta(t)}2\alpha_t, \qquad\beta(t)=-2\frac{d}{dt}\log\alpha_t.}\]

Thus the \(\alpha_t\) used to generate training examples determines the \(\beta(t)\) in the sampling field \(v(x,t)=-\beta(t)[x+s_t(x)]/2\). Appendix C derives the small-step limit, cumulative amplitude, and conditional variance. Data are at time zero; the standard Gaussian used at time one approximates the actual terminal law for a finite-rate schedule.

Quantity Formula Role
Instantaneous rate \(\beta(t)\) Rate in the forward SDE and sampling ODE
Cumulative signal amplitude \(\alpha_t\) Multiplies the clean observation
Conditional noise variance \(1-\alpha_t^2\) Accumulated variance in a training example
Conditional noise standard deviation \(\sqrt{1-\alpha_t^2}\) Multiplies sampled Gaussian noise

Constant rate in Part 1; linear rate in the paper

The earlier Part 4 notebooks (including 03-learn-a-score.ipynb) use \(\beta(t)=8\), hence \(\alpha_t=e^{-4t}\) and conditional variance \(1-e^{-8t}\). Their training code and ODE both use this constant rate. It is a valid VP example, not the paper’s experimental linear schedule.

For the paper’s linear VP schedule on \([0,1]\), write its endpoint rates in our notation as

\[\beta(t)=\beta_{\min}+t(\beta_{\max}-\beta_{\min}),\qquad \beta_{\min}=0.1,\quad\beta_{\max}=20.\]

Integrating this rate gives

\[\boxed{\alpha_t=\exp\!\left[-\frac{\beta_{\min}t}{2} -\frac{(\beta_{\max}-\beta_{\min})t^2}{4}\right].}\]

The forward training example is therefore

\[X_t=\alpha_tX_0+\sqrt{1-\alpha_t^2}\,\varepsilon,\]

and its sampling field uses \(\beta(t)=0.1+19.9t\), evaluated at the current solver time. Replacing this coefficient by 8 while keeping the linear-schedule training data would give the wrong field for the learned density path.

For this linear schedule, \(\alpha_1=e^{-5.025}\approx0.00657\). The terminal law generally retains a small data contribution; it is not exactly standard normal. Increasing the number of Euler steps does not reduce that terminal-prior approximation. The constant-rate notebooks likewise retain \(\alpha_1=e^{-4}\). Part 6 uses the linear schedule developed here, with \(t_{\min}=0.001\).

2. Start with supervised denoising

Generate joint pairs using the forward process

Fix a positive time \(t\) with \(0<\alpha_t<1\). Draw independently

\[X_0\sim p_{\mathrm{data}},\qquad \varepsilon\sim\mathcal N(0,1),\]

and construct

\[X_t=\alpha_tX_0+\sqrt{1-\alpha_t^2}\,\varepsilon.\]

We now have a supervised pair: the noisy input \(X_t\) and its clean label \(X_0\). We know the realized noise because we generated the pair, not because \(X_t\) alone determines that noise.

The forward construction samples the joint distribution

\[p(x_0,x_t)=p_{\mathrm{data}}(x_0)\,p_t(x_t\mid x_0).\]

We need not know this joint density analytically: clean samples and a known forward conditional are enough to sample pairs. With finite data, sampling clean observations uniformly uses the empirical data distribution. In that case, the optimal regression function below is the posterior mean under the empirical law, not exactly the population law; Appendix D makes this distinction explicit.

Learn the clean value from the noisy input

Give the network only \((X_t,t)\) and ask it to predict \(X_0\). At this fixed time, the objective is

\[\boxed{\mathcal L_{D,t}(\theta)= \mathbb E_{X_0\sim p_{\mathrm{data}},\,\varepsilon\sim\mathcal N(0,1)} \left[(D_\theta(X_t,t)-X_0)^2\right].}\]

Assume the clean distribution has a finite second moment. By the law of total expectation, the same loss is

\[\mathcal L_{D,t}(\theta)=\mathbb E_{X_t\sim p_t} \left[\mathbb E_{X_0\mid X_t} \left[(D_\theta(X_t,t)-X_0)^2\right]\right].\]

At a fixed noisy input \(x\), let \(m_t(x)=\mathbb E_{X_0\mid X_t=x}[X_0]\). For any proposed output \(a\),

\[\mathbb E_{X_0\mid X_t=x}[(a-X_0)^2] =(a-m_t(x))^2+\operatorname{Var}(X_0\mid X_t=x).\]

Only the first term depends on \(a\). Thus the unrestricted optimal denoiser is

\[\boxed{D_*(x,t)=m_t(x)=\mathbb E_{X_0\mid X_t=x}[X_0].}\]

This is the posterior mean, not the full posterior distribution and not necessarily the historical clean input used in a particular pair. Different clean values with different noise draws can produce the same noisy observation.

NoteForward-generated pairs support reverse-direction estimation

Before corruption, \(X_0\) and \(\varepsilon\) are independent. Given \(X_t=x\), they are linked by

\[\varepsilon=\frac{x-\alpha_tX_0}{\sqrt{1-\alpha_t^2}}.\]

Training uses samples from their joint construction. Squared-error regression on the noisy input has a posterior conditional mean as its optimum. We do not evaluate the posterior density, draw posterior samples, or average independently over clean values after fixing \(x\). Nor do we need repeated training observations with exactly the same noisy value: a shared regression function is fitted across inputs.

To train one network across time, additionally draw \(t\sim\operatorname{Uniform}[t_{\min},1]\), independently of \(X_0\) and \(\varepsilon\), and minimize

\[\mathcal L_D(\theta)=\mathbb E_{t,X_0,\varepsilon} [(D_\theta(X_t,t)-X_0)^2].\]

The expectation uses exactly those three independent draws before forming \(X_t\). At the unrestricted optimum, the network gives the posterior mean at each trained time. Finite data, restricted networks, and optimization introduce approximation error.

3. From the posterior mean to the score required by the ODE

Tweedie’s identity supplies the conversion

The denoiser answers a natural estimation question. We now connect its solution to the quantity needed for sampling. Let \(p_{\mathrm{data}}(u)\) denote the clean-data density. At fixed positive time, differentiate the noisy marginal:

\[\begin{aligned} p_t(x)&=\int p_t(x\mid u)\,p_{\mathrm{data}}(u)\,du,\\ \partial_xp_t(x) &=\int \frac{\alpha_tu-x}{1-\alpha_t^2}\,p_t(x\mid u)\,p_{\mathrm{data}}(u)\,du. \end{aligned}\]

Here \(u\) is a possible clean value; the noisy observation \(x\) and time \(t\) are held fixed. First divide by the noisy marginal density, which is positive at positive Gaussian noise:

\[\begin{aligned} s_t(x) &=\frac{\partial_xp_t(x)}{p_t(x)}\\ &=\int\frac{\alpha_tu-x}{1-\alpha_t^2} \frac{p_t(x\mid u)}{p_t(x)}\,p_{\mathrm{data}}(u)\,du. \end{aligned}\]

Bayes’ rule identifies the weighting explicitly:

\[\boxed{p(u\mid X_t=x) =\frac{p_t(x\mid u)\,p_{\mathrm{data}}(u)}{p_t(x)}, \qquad p_t(x)=\int p_t(x\mid u)\,p_{\mathrm{data}}(u)\,du.}\]

The numerator weights each possible clean value by its prior density and the likelihood of the observed noisy value. The denominator normalizes those weights. Substituting into the score integral gives

\[\begin{aligned} s_t(x) &=\int\frac{\alpha_tu-x}{1-\alpha_t^2} \underbrace{\frac{p_t(x\mid u)p_{\mathrm{data}}(u)}{p_t(x)}}_{p(u\mid X_t=x)}\,du\\ &=\frac{1}{1-\alpha_t^2} \left[\alpha_t\int u\,p(u\mid X_t=x)\,du -x\int p(u\mid X_t=x)\,du\right]\\ &=\frac{1}{1-\alpha_t^2} \left[\alpha_t\,\mathbb E_{X_0\mid X_t=x}[X_0]-x\cdot1\right]. \end{aligned}\]

The first integral is the definition of the posterior mean; the second equals one because the posterior is a probability density. We can take \(x\) outside the integral because it is the fixed observation, not the integration variable.

For discrete or empirical clean data, replace the integrals by sums, as shown in Appendix D. Thus

\[\boxed{s_t(x)=\partial_x\log p_t(x) =\frac{\alpha_t\mathbb E_{X_0\mid X_t=x}[X_0]-x}{1-\alpha_t^2} =\frac{\alpha_tD_*(x,t)-x}{1-\alpha_t^2}.}\]

This is the VP form of Tweedie’s formula. The score is a scaled displacement involving the posterior mean; it is not itself that mean. Appendix A gives the standalone additive-noise derivation, and Appendix D gives an alternative proof using mixture components.

NoteInterpretation: possible clean origins of a noisy observation

Fix the observed noisy position \(X_t=x\). Different clean values \(x_0\), combined with different noise realizations, could have produced this observation. For each candidate clean value, the required noise is

\[\varepsilon=\frac{x-\alpha_tx_0}{\sqrt{1-\alpha_t^2}}.\]

We weight these possible clean origins by their posterior probabilities: a candidate is more plausible when it is supported by the clean-data distribution and the required noise is plausible. The weights are proportional to \(p_{\mathrm{data}}(x_0)p_t(x\mid x_0)\), not equal across candidates.

Their weighted mean is \(m_t(x)=\mathbb E[X_0\mid X_t=x]\). The score is the corresponding average conditional-score displacement:

\[\boxed{s_t(x)=\mathbb E_{X_0\mid X_t=x} \left[\frac{\alpha_tX_0-x}{1-\alpha_t^2}\right] =\frac{\alpha_tm_t(x)-x}{1-\alpha_t^2}.}\]

Thus the posterior mean of the possible clean origins determines the marginal score; the score is not the mean itself. The clean origins are scaled by \(\alpha_t\) before subtracting the noisy position, and the displacement is divided by the noise variance.

Forward-generated training pairs supply conditional-score labels \((\alpha_tX_0-X_t)/(1-\alpha_t^2)\), denoted \(U\) below. Squared-error regression with \((X_t,t)\) as input learns this posterior-weighted average at its unrestricted population optimum, without explicitly evaluating the posterior.

These are possible origins under stochastic corruption, not terminal points of deterministic backward ODE trajectories. The probability-flow ODE uses the resulting score to transport the whole density; it need not recover the historical clean origin of an individual noisy observation. The local score reflects the originating distribution, but the sampler needs only the current position and time, not a stored trajectory. Appendix D.6 develops this distinction.

A fitted denoiser therefore defines the estimates

\[s_\theta(x,t)=\frac{\alpha_tD_\theta(x,t)-x}{1-\alpha_t^2}, \qquad v_\theta(x,t)=-\frac{\beta(t)}2[x+s_\theta(x,t)].\]

The second formula is precisely the probability-flow field from Part 1. Generating samples requires integrating this field backward from the terminal distribution. Applying \(D_\theta\) once is not generally a sampling procedure: posterior means need not have the clean-data distribution.

NoteConnection to inference: the denoised estimate determines the Euler step

Although this part focuses on training, substituting Tweedie’s formula directly into the sampler makes clear how the learned posterior mean is used. Write \(m_t(x)=\mathbb E[X_0\mid X_t=x]=D_*(x,t)\). For \(0<\alpha_t<1\),

\[\begin{aligned} v(x,t) &=-\frac{\beta(t)}2\left[x+\frac{\alpha_tm_t(x)-x}{1-\alpha_t^2}\right]\\ &=\frac{\beta(t)\alpha_t}{2(1-\alpha_t^2)} \left[\alpha_tx-m_t(x)\right]. \end{aligned}\]

An explicit Euler step with decreasing time, from \(t\) to \(t-h\) with \(h>0\), is therefore

\[\boxed{ x_{t-h}=x_t-hv(x_t,t) =x_t+\frac{h\beta(t)\alpha_t}{2(1-\alpha_t^2)} \left[\underbrace{\mathbb E[X_0\mid X_t=x_t]}_{\text{denoised estimate}} -\alpha_tx_t\right]. }\]

The score no longer appears explicitly. At each step, the model estimates the clean observation from the current noisy position, and the known schedule converts that estimate into a transport step. In practice, replace the posterior mean by \(D_\theta(x_t,t)\); a score or noise predictor supplies the equivalent denoised estimate through the identities in this part.

The velocity is determined by the denoised estimate, the current position, and the schedule; it is not itself the denoised estimate. The displacement involves \(m_t(x_t)-\alpha_tx_t\), so the VP scaling matters. Repeating the small transport steps generates an approximate sample. It does not replace the particle by its posterior mean in one step or recover its particular historical clean origin. Here Euler with decreasing time is the explicit method, not the implicit numerical method called backward Euler.

Additive-noise notation for the examples

For the first example, use \(Y=X+\sigma\varepsilon\) with independent \(X\sim p_X\), \(\varepsilon\sim\mathcal N(0,1)\), and \(\sigma>0\). The same posterior-mean identity becomes

\[D_*(y)=\mathbb E_{X\mid Y=y}[X] =y+\sigma^2\partial_y\log p_Y(y).\]

Appendix A gives its standalone derivation. The second example uses the VP notation developed above.

Two solved denoising examples

A Gaussian prior

Let \(X\sim\mathcal N(\mu,V)\) and \(Y=X+\sigma \varepsilon\). Then

\[p_Y=\mathcal N(\mu,V+\sigma^2),\qquad \frac{d}{dy}\log p_Y(y)=-\frac{y-\mu}{V+\sigma^2}.\]

Tweedie’s formula gives

\[\mathbb E_{X\mid Y=y}[X] =\mu+\frac{V}{V+\sigma^2}(y-\mu).\]

At small noise, the posterior mean stays close to \(y\). At large noise, it stays close to the prior mean. The posterior variance is \(V\sigma^2/(V+\sigma^2)\); the mean alone does not represent this remaining uncertainty.

Two equally likely clean values

Let \(P(X_0=1)=P(X_0=-1)=1/2\). At a positive diffusion time, Bayes’ rule gives posterior log odds

\[\log\frac{P(X_0=1\mid X_t=x)}{P(X_0=-1\mid X_t=x)} =\frac{2\alpha_tx}{1-\alpha_t^2}.\]

Consequently,

\[\mathbb E_{X_0\mid X_t=x}[X_0] =\tanh\left(\frac{\alpha_tx}{1-\alpha_t^2}\right),\]

\[s_t(x)=\frac{\alpha_t\tanh(\alpha_tx/(1-\alpha_t^2))-x}{1-\alpha_t^2}.\]

At \(x=0\), the posterior mean is zero, although clean observations are only \(-1\) or \(+1\). A posterior sample is one of those two values. This is why a single posterior-mean denoising operation generally does not generate the clean-data distribution.

For each fixed nonzero \(x\), the posterior mean tends to \(\operatorname{sign}(x)\) as noise vanishes. At \(x=0\), it remains zero by symmetry. This discrete clean distribution also illustrates why smooth invertible flow statements are made at positive noise or under appropriate endpoint regularity.

Conditional-score supervision is a transformed clean-data label

For a forward-generated pair, define

\[U=\frac{\alpha_tX_0-X_t}{1-\alpha_t^2} =\partial_{X_t}\log p_t(X_t\mid X_0).\]

At fixed input \(X_t=x\), this label is an affine transformation of \(X_0\). Its squared-error-optimal prediction is therefore the same transformation of the posterior mean:

\[\boxed{\mathbb E_{U\mid X_t=x}[U] =\frac{\alpha_tD_*(x,t)-x}{1-\alpha_t^2}=s_t(x).}\]

This explains why we can supervise with a conditional score while predicting the marginal score. The known forward conditional provides the training label; regression on the noisy input performs the reverse-direction averaging.

For predictions related by the denoiser-to-score conversion, the samplewise errors obey

\[(s_\theta(X_t,t)-U)^2 =\frac{\alpha_t^2}{(1-\alpha_t^2)^2} (D_\theta(X_t,t)-X_0)^2.\]

At a fixed positive time this is a positive rescaling of the denoising loss. Across time it changes the weighting, so unweighted clean-data and score losses need not train a finite network identically. We can now interpret the paper’s objective as regression with these transformed labels.

Song et al.’s Eq. (7): training with conditional-score labels

With the paper’s terminal time normalized to 1, its population objective is

\[\begin{aligned} \mathcal J_s^{\mathrm{paper}}(\theta) &=\mathbb E_{t\sim\operatorname{Uniform}[0,1]}\Bigg[ \lambda(t)\, \mathbb E_{X_0\sim p_{\mathrm{data}}}\Big[ \mathbb E_{X_t\sim p_{0t}(\cdot\mid X_0)} \big[(s_\theta(X_t,t)-\partial_{X_t}\log p_{0t}(X_t\mid X_0))^2\big] \Big]\Bigg]. \end{aligned}\]

The notation \(p_{0t}(\cdot\mid x_0)\) is the paper’s forward transition law from time 0 to time \(t\); it is the same conditional density denoted \(p_t(\cdot\mid x_0)\) in these notes. The three averages mean:

  1. Draw time \(t\) uniformly on \([0,1]\).
  2. Draw a clean observation \(X_0\) from \(p_{\mathrm{data}}\).
  3. Holding that time and clean observation fixed, draw \(X_t\) from \(p_{0t}(\cdot\mid X_0)\).

In particular, the innermost expectation is over the conditional forward distribution, not an independent draw from the marginal \(p_t\), and not the posterior \(p(X_0\mid X_t)\). The posterior characterizes the denoising solution in Section 2; the training pairs are drawn in the forward direction. With a finite dataset, the clean-data expectation is approximated by sampling observations from its empirical distribution.

For VP diffusion,

\[p_{0t}(\cdot\mid x_0)=\mathcal N(\alpha_t x_0,1-\alpha_t^2).\]

Consequently, sampling independent \(\varepsilon\sim\mathcal N(0,1)\) and forming \(X_t=\alpha_tX_0+\sqrt{1-\alpha_t^2}\varepsilon\) is exactly a reparameterization of that innermost conditional expectation. It is not a different training distribution.

For the generated pair, the label defined above is \(U=-\varepsilon/\sqrt{1-\alpha_t^2}\). The network sees \((X_t,t)\), not the clean label \(X_0\) as an input.

The practical, positive-time version

Eq. (7) uses the full time interval. In the implementation here, \(t\sim\operatorname{Uniform}[t_{\min},1]\) instead: this is an explicitly truncated training objective, not literally the same time distribution as Eq. (7). It avoids the zero-variance conditional kernel at time zero. The score-regression identity is unchanged on the retained times, but the objective gives no direct training constraint below \(t_{\min}\).

For this practical loss, average over three independent draws before constructing \(X_t\):

\[t\sim\operatorname{Uniform}[t_{\min},1],\qquad X_0\sim p_{\mathrm{data}},\qquad \varepsilon\sim\mathcal N(0,1), \qquad X_t=\alpha_tX_0+\sqrt{1-\alpha_t^2}\,\varepsilon.\]

We write this joint average as \(\mathbb E_{t,X_0,\varepsilon}\). The noisy input \(X_t\) is computed from these draws; it is not drawn independently of them. A positive \(t_{\min}\) excludes the zero-noise endpoint.

The resulting denoising score-matching loss is

\[\boxed{\mathcal J_s(\theta)=\mathbb E_{t,X_0,\varepsilon}\left[ \lambda(t)\left(s_\theta(X_t,t)+\frac{\varepsilon}{\sqrt{1-\alpha_t^2}}\right)^2\right]}\]

and we train by minimizing it over \(\theta\). The regression argument below explains why it has the desired population solution \(s_\theta(x,t)=s_t(x)\), for positive weights on the times being trained and sufficient model capacity. Finite datasets, restricted networks, and optimization error make practical estimates approximate. This is the Gaussian reparameterization of Song et al., Eq. (7), with the positive-time cutoff stated above.

The regression decomposition

The posterior identity above can also be written in terms of noise:

\[s_t(x)=\mathbb E_{X_0\mid X_t=x}[\partial_x\log p_t(x\mid X_0)] =-\frac{\mathbb E_{\varepsilon\mid X_t=x}[\varepsilon]}{\sqrt{1-\alpha_t^2}}.\]

Time is fixed in these conditional expectations. The input \(x\) is held fixed while compatible clean/noise pairs are averaged under their posterior law.

Squared-error regression estimates the conditional mean of its target given the input. Here the input is \((X_t,t)\), the target is \(U\), and the identity above identifies that conditional mean with \(s_t(X_t)\). More explicitly, the loss decomposes as (see Appendix B for the conditional squared-error expansion)

\[\mathcal J_s(\theta) =\mathbb E_{t,X_t}\left[\lambda(t)(s_\theta(X_t,t)-s_t(X_t))^2\right] +\mathbb E_{t,X_t}\left[\lambda(t)\operatorname{Var}(U\mid X_t,t)\right].\]

Here \(\mathbb E_{t,X_t}\) means first draw \(t\sim\operatorname{Uniform}[t_{\min},1]\), then \(X_t\sim p_t\). These two variables are generally dependent. Inside the conditional variance, \(X_t\) and \(t\) are held fixed and the remaining randomness is in \(U\) (equivalently, the clean/noise pairs compatible with that observation).

The second term does not depend on the network. Training against conditional targets minimizes the same parameter-dependent error as training against the unavailable marginal score.

Why the noisy position must be an input

Fix \(t\) and a noisy input \(x\). If the predictor outputs a scalar \(a\) there, its conditional risk is

\[R(a;x,t)=\mathbb E_{U\mid X_t=x,t}[(a-U)^2].\]

Expanding and differentiating with respect to \(a\) gives

\[\frac{\partial R}{\partial a}=2a-2\mathbb E_{U\mid X_t=x,t}[U], \qquad a_*(x,t)=\mathbb E_{U\mid X_t=x,t}[U]=s_t(x).\]

The average is over targets compatible with that input, not over all training targets indiscriminately. Although the target has mean zero at each time,

\[\mathbb E_{X_0,\varepsilon}[U]=0,\]

its conditional mean given \(X_t=x\) need not vanish. The noisy position depends on both the clean observation and the noise. If we withheld \(X_t\) and supplied only time, squared-error regression would indeed learn zero. With \(X_t\) as a feature, it can learn a nonzero function of position.

There are two different conditioning directions:

\[\underbrace{\mathbb E_{X_t\mid X_0=x_0}[\partial_{X_t}\log p_t(X_t\mid x_0)]}_{\text{hold clean value fixed; average noisy observations}}=0,\]

whereas

\[\underbrace{\mathbb E_{X_0\mid X_t=x}[\partial_x\log p_t(x\mid X_0)]}_{\text{hold noisy value fixed; average compatible clean values}}=s_t(x).\]

For the Gaussian kernel, the first equality follows directly from \(\mathbb E[X_t\mid X_0=x_0]=\alpha_t x_0\). It does not imply that the second expectation is zero.

A zero conditional-score label can have a nonzero optimal prediction

Take \(X_0\sim\mathcal N(0,1)\) and fix a positive time with \(\alpha_t=1/2\). Then

\[X_t=\tfrac12X_0+\tfrac{\sqrt3}{2}\varepsilon, \qquad p_t(x)=\mathcal N(x;0,1),\qquad s_t(x)=-x.\]

Consider the clean value \(x_0=2\) and noisy value \(x_t=1\), corresponding to the noise value \(\varepsilon=0\). The conditional-score label for this pair is

\[\left.\partial_x\log p_t(x\mid x_0=2)\right|_{x=1} =-\frac{1-\tfrac12(2)}{3/4}=0.\]

But the marginal score at exactly the same noisy input is

\[\boxed{s_t(1)=-1\ne0.}\]

Why? Given only \(X_t=1\), the clean value is not known to be 2. Gaussian conditioning gives

\[X_0\mid X_t=1\sim\mathcal N(1/2,3/4).\]

Averaging the conditional-score labels under this posterior yields

\[\mathbb E_{X_0\mid X_t=1}\left[-\frac{1-\tfrac12X_0}{3/4}\right] =-\frac{1-\tfrac12(1/2)}{3/4}=-1.\]

Thus zero is the label of one particular pair; \(-1\) is the squared-error-optimal prediction using the available features. Exact point events have probability zero under continuous distributions; the example evaluates the score functions at a point. Nearby pairs have small conditional-score labels while their marginal scores remain close to \(-1\), so the distinction also holds on neighborhoods with positive probability.

This does not say that an average of identically zero labels can be nonzero. Other clean values compatible with the same noisy observation have different labels. Also, because this example starts from standard normal, its VP probability-flow velocity is \(-\beta(t)[x+s_t(x)]/2=0\), even though its marginal score is nonzero away from the origin.

Alternative explanation: each observed data point is a mixture component

A finite dataset can be viewed as a mixture of point masses. Gaussian corruption turns it into a Gaussian mixture, with one component centered at each scaled observation. At a noisy input \(x\), the marginal score is the average of these component scores weighted by their posterior probabilities given \(x\). These input-dependent weights explain why one conditional-score label can be zero while the marginal-score prediction is not.

Appendix D develops this argument step by step: two clean points, a finite dataset, and an arbitrary population distribution. The same calculation gives Tweedie’s formula. It is an alternative explanation of the identity above, not an assumption that the clean population must be a finite Gaussian mixture.

4. Noise prediction as a parameterization of the marginal score

A numerically convenient network output is \(\varepsilon_\theta(x,t)\), trained with

\[\mathcal J_\varepsilon(\theta) =\mathbb E_{t,X_0,\varepsilon}[(\varepsilon-\varepsilon_\theta(X_t,t))^2].\]

This expectation uses the same time, clean-data, and Gaussian-noise draws defined in Section 2. At the population optimum, \(\varepsilon_*(x,t)=\mathbb E_{\varepsilon\mid X_t=x}[\varepsilon]\). Convert any noise predictor to a score estimate using

\[\boxed{s_\theta(x,t)=-\frac{\varepsilon_\theta(x,t)}{\sqrt{1-\alpha_t^2}}.}\]

The phrase noise predictor names the regression target and output units. It does not mean that the fitted model recovers the particular noise draw in each training pair. Its optimal output is a posterior mean of noise. Only after the scaling above do we obtain the marginal-score estimate.

Parameterization Label available for each training pair Population prediction from \((x,t)\)
Clean data Realized \(X_0\) \(D_*(x,t)=\mathbb E[X_0\mid X_t=x,t]\)
Direct score \(U=-\varepsilon/\sqrt{1-\alpha_t^2}\), the conditional score \(\mathbb E[U\mid X_t=x,t]=s_t(x)\)
Noise Realized \(\varepsilon\) \(\mathbb E[\varepsilon\mid X_t=x,t]=-\sqrt{1-\alpha_t^2}\,s_t(x)\)

In the preceding Gaussian example, \(\operatorname{Cov}(\varepsilon,X_t)=\sqrt{1-\alpha_t^2}\) and \(\operatorname{Var}(X_t)=1\). Joint Gaussian conditioning therefore gives

\[\varepsilon_*(x,t)=\sqrt{1-\alpha_t^2}\,x.\]

At \(\alpha_t=1/2\) and \(x=1\), the optimal noise prediction is \(\sqrt3/2\), although the particular pair used above had noise label zero. Dividing by the negative noise standard deviation gives the correct marginal score \(-1\). There is no inconsistency: a regression prediction minimizes expected error across possible labels, not the error of every pair separately.

You can also construct a clean-data predictor:

\[\boxed{\widehat x_{0,\theta}(x,t) =\frac{x-\sqrt{1-\alpha_t^2}\,\varepsilon_\theta(x,t)}{\alpha_t}.}\]

These are exact algebraic conversions of predictions. They do not imply that three unweighted training losses emphasize the same times. For predictions related by these conversions, the samplewise errors satisfy

\[\begin{aligned} (\varepsilon-\varepsilon_\theta)^2 &=(1-\alpha_t^2)(U-s_\theta)^2,\\ (X_0-\widehat x_{0,\theta})^2 &=\frac{1-\alpha_t^2}{\alpha_t^2}(\varepsilon-\varepsilon_\theta)^2. \end{aligned}\]

Thus uniform-time noise prediction is a particular time weighting of score matching. Near zero noise, dividing prediction error by \(\sqrt{1-\alpha_t^2}\) amplifies score error. Near the terminal time, a small \(\alpha_t\) amplifies errors in clean-data prediction.

Why noise prediction can be easier to optimize

At a fixed positive time, average over the independent clean-data and noise draws. The conditional-score target \(U=-\varepsilon/\sqrt{1-\alpha_t^2}\) satisfies

\[\mathbb E_{X_0\sim p_{\mathrm{data}},\,\varepsilon\sim\mathcal N(0,1)}[U^2] =\frac1{1-\alpha_t^2},\qquad \mathbb E_{\varepsilon\sim\mathcal N(0,1)}[\varepsilon^2]=1.\]

The raw conditional-score targets grow near zero noise, whereas the noise targets have the same second moment at every time. Noise prediction avoids regressing directly onto these increasingly large targets. Algebraically, its unweighted MSE corresponds to score matching with \(\lambda(t)=1-\alpha_t^2\), for the same time-sampling law.

Song et al.’s Section 3.3 recommends weighting inversely to the conditional-score target’s expected squared norm. In one-dimensional VP diffusion this gives \(\lambda(t)\propto1-\alpha_t^2\), exactly the weighting above. In \(d\) dimensions the second moment is \(d/(1-\alpha_t^2)\), giving the same time weighting up to a constant.

This is a useful scaling choice, not a guarantee of better optimization for every model. Appropriately weighted direct score prediction is also valid. Converting a fitted noise predictor back to a score still divides its error by \(\sqrt{1-\alpha_t^2}\); a stable training loss does not guarantee an accurate low-noise score. Evaluate the score at small positive times as well as the average training loss.

5. An explicit algorithm for training the network

Use a time-conditioned network \(\varepsilon_\theta(x,t)\) with one scalar output in one dimension. Given a dataset, a fixed VP schedule, and a cutoff \(t_{\min}>0\):

  1. Initialize the network parameters and optimizer.
  2. Draw a minibatch of clean observations uniformly from the dataset.
  3. Independently for each observation, draw \(t\sim\operatorname{Uniform}[t_{\min},1]\) and \(\varepsilon\sim\mathcal N(0,1)\).
  4. Compute \(\alpha_t\) from the chosen schedule and form \(x_t=\alpha_tx_0+\sqrt{1-\alpha_t^2}\varepsilon\).
  5. Predict \(\varepsilon_\theta(x_t,t)\) and average its squared error against the sampled noise over the minibatch.
  6. Backpropagate this loss and update the parameters. Repeat with fresh times and noise.
  7. Evaluate on held-out observations; save the fitted parameters, schedule, and time range. At generation time, freeze the model and use \(s_\theta=-\varepsilon_\theta/\sqrt{1-\alpha_t^2}\).

The network receives the noisy position and time, not the clean observation or the sampled noise. A minibatch average estimates the noise-regression expectation in Section 4; it is not an additional density-estimation step. No ODE solver is needed during this training procedure.

PyTorch implementation

This minimal network uses position and time directly. Part 6 adds fixed sinusoidal time features to the same inputs; these change the network representation, not the schedule or objective.

The code below uses the paper’s linear VP schedule. Setting both endpoint rates to 8 recovers the teaching notebooks’ constant schedule. The data tensor has shape [number_of_observations, 1]; flattening images or vectors gives [number_of_observations, data_dimension].

import torch

beta_min, beta_max = 0.1, 20.0

def beta(t):
    return beta_min + (beta_max - beta_min) * t

def vp_coefficients(t):
    integrated_beta = beta_min*t + 0.5*(beta_max-beta_min)*t.square()
    alpha = torch.exp(-0.5 * integrated_beta)
    # expm1 avoids cancellation at small positive times.
    noise_variance = -torch.expm1(-integrated_beta)
    return alpha, noise_variance.sqrt()

def noise_loss(network, x0, t_min=1e-3):
    # x0 has shape [batch, data_dimension]; fresh t and noise each update.
    t = t_min + (1-t_min)*torch.rand(len(x0), device=x0.device,
                                   dtype=x0.dtype)
    alpha, noise_std = vp_coefficients(t)
    eps = torch.randn_like(x0)
    xt = alpha[:, None]*x0 + noise_std[:, None]*eps
    return (network(xt, t) - eps).square().mean()


class NoisePredictor(torch.nn.Module):
    def __init__(self, data_dimension=1):
        super().__init__()
        self.net = torch.nn.Sequential(
            torch.nn.Linear(data_dimension + 1, 64), torch.nn.SiLU(),
            torch.nn.Linear(64, 64), torch.nn.SiLU(),
            torch.nn.Linear(64, data_dimension))

    def forward(self, x, t):
        return self.net(torch.cat([x, t[:, None]], dim=1))

def train_score_model(data, updates=2500, batch_size=512, t_min=1e-3):
    model = NoisePredictor(data.shape[1]).to(device=data.device,
                                           dtype=data.dtype)
    optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
    model.train()
    history = []
    for _ in range(updates):
        indices = torch.randint(len(data), (batch_size,), device=data.device)
        loss = noise_loss(model, data[indices], t_min=t_min)
        optimizer.zero_grad(set_to_none=True)
        loss.backward()
        optimizer.step()
        history.append(loss.item())
    model.eval()
    return model, history

For vectors, the Gaussian noise is \(\mathcal N(\mathbf0,I_d)\) and the network predicts one noise component per data coordinate. The code averages over coordinates as well as observations; this differs from the squared Euclidean norm by the fixed factor \(1/d\) and has the same minimizer. The vector score conversion is \(\mathbf s_\theta=-\boldsymbol\varepsilon_\theta/\sqrt{1-\alpha_t^2}\).

This code and Part 6 use cutoff \(10^{-3}\); the earlier Part 4 notebook 03-learn-a-score.ipynb uses \(0.01\). Train and sample on compatible time ranges. In this code, beta_min and beta_max are globals read by both training and sampling; do not change them between those operations. Keep the schedule parameters with the saved model: changing the schedule after fitting changes the density associated with each time. An average noise loss need not approach zero because the noise is uncertain given \((X_t,t)\).

6. Using the trained model for generation

Freeze the network. At every solver evaluation, convert its output to a score and evaluate

\[\mathbf v_\theta(\mathbf x,t) =-\frac{\beta(t)}2\left[\mathbf x- \frac{\boldsymbol\varepsilon_\theta(\mathbf x,t)}{\sqrt{1-\alpha_t^2}}\right].\]

For exact transport, start with a sample from the actual terminal law \(p_1\) and integrate toward smaller \(t\). In the practical VP sampler below, we use standard normal as an approximation to that law. An ODE step uses no fresh randomness. A reverse-SDE step adds the appropriate Gaussian increment, as specified in Part 2.

For \(h=t_k-t_{k+1}>0\), the explicit reverse-time Euler update is

\[\boxed{x_{k+1}=x_k+\frac{h\beta(t_k)}2 \left[x_k-\frac{\varepsilon_\theta(x_k,t_k)}{\sqrt{1-\alpha_{t_k}^2}}\right].}\]

The plus sign comes from integrating \(v_\theta\) over the negative increment \(-h\). This is explicit Euler run backward in time, not the implicit backward-Euler method. The reverse SDE instead uses a full \(\beta(t_k)s_\theta\) score term and adds noise; removing its noise term does not give this ODE.

Euler sampler using the schedule and network from Section 5

@torch.no_grad()
def sample_ode(network, x1, steps=1000, t_min=1e-3):
    network.eval()
    x = x1.clone()  # Supply draws from p1, or explicitly use a prior approximation.
    times = torch.linspace(1., t_min, steps+1, device=x.device,
                           dtype=x.dtype)
    for current, next_time in zip(times[:-1], times[1:]):
        t = current.expand(len(x))
        _, noise_std = vp_coefficients(t)
        score = -network(x, t) / noise_std[:, None]
        h = current - next_time
        x = x + 0.5*h*beta(t)[:, None]*(x + score)
    return x  # intended law: p(t_min), subject to approximation errors

Use the fitted model from Section 5 and supply independent standard-normal x1. The sampler’s cutoff must lie in the trained range. There are no optimizer updates or fresh noise draws inside this ODE loop.

Run training and generation end to end

Run the definitions in Section 5 and the sampler above first. This CPU example uses the same two-component Gaussian data distribution as the teaching notebooks. The schedule remains the linear VP schedule defined in Section 5.

import matplotlib.pyplot as plt

torch.manual_seed(20261006)
torch.set_num_threads(2)
component = 2*torch.randint(0, 2, (10000, 1)) - 1
data = 2*component.float() + 0.5*torch.randn(10000, 1)
model, history = train_score_model(data, updates=2500, t_min=1e-3)
x1 = torch.randn(5000, 1)
samples = sample_ode(model, x1, steps=1000, t_min=1e-3)
assert torch.isfinite(samples).all()

# Compare with an independent draw from the intended positive-time law.
component = 2*torch.randint(0, 2, (5000, 1)) - 1
reference_clean = 2*component.float() + 0.5*torch.randn(5000, 1)
a, noise_std = vp_coefficients(torch.tensor(1e-3))
reference = a*reference_clean + noise_std*torch.randn_like(reference_clean)
fig, axes = plt.subplots(1, 2, figsize=(10, 3))
axes[0].plot(history)
axes[0].set(xlabel="Training update", ylabel="Minibatch noise MSE")
axes[1].hist(reference.numpy().ravel(), bins=70, density=True,
             alpha=0.5, label="Reference p(t_min)")
axes[1].hist(samples.numpy().ravel(), bins=70, density=True,
             alpha=0.5, label="Generated")
axes[1].set(xlabel="Position", ylabel="Density")
axes[1].legend()
plt.tight_layout()
plt.show()

This comparison checks the complete procedure, not convergence to an exact solution. The intended output is \(p_{0.001}\); learned-score error, Gaussian terminal initialization, and finite Euler steps remain approximations. Part 6 provides the executed end-to-end experiment and detailed fidelity checks.

Analytic check of the schedule and solver

This Gaussian check tests the schedule and sign with a velocity independent of position; its Euler error is a quadrature error. Part 6 also checks state-dependent mixture dynamics against exact quantile transport.

The probability-flow construction does not require a standard-normal terminal law. It requires that initialization match the terminal density of the forward process used to derive the score and velocity. Changing the terminal distribution alone generally breaks that match.

For a fully matched Gaussian example, take \(P_0=\mathcal N(\mu,1)\) and retain the VP schedule above. The forward corruption gives

\[p_t(x)=\mathcal N(x;\alpha_t\mu,1),\qquad P_1=\mathcal N(\alpha_1\mu,1).\]

The score and velocity of this same density path are

\[s_t(x)=-(x-\alpha_t\mu),\qquad v(x,t)=-\tfrac12\beta(t)\alpha_t\mu=\alpha_t'\mu.\]

Now initialize from its actual terminal law:

\[\varepsilon\sim\mathcal N(0,1),\qquad X_1=\alpha_1\mu+\varepsilon.\]

Integrating the ODE backward gives

\[X_t=X_1+(\alpha_t-\alpha_1)\mu =\alpha_t\mu+\varepsilon.\]

Consequently, \(X_t\) has density \(p_t\) at every time and \(X_0=\mu+\varepsilon\sim\mathcal N(\mu,1)\) exactly for the exact flow. This example has no terminal-prior approximation. Comparing Euler endpoints with this trajectory isolates numerical error. For \(\mu=0\), the score is \(-x\) and the probability-flow velocity is zero.

A separate approximation experiment: if we replace this matched initialization by \(X_1\sim\mathcal N(0,1)\) while leaving the field unchanged, the output at time zero is \(\mathcal N((1-\alpha_1)\mu,1)\), not \(P_0\). Its mean error is \(-\alpha_1\mu\). This quantifies the cost of substituting a convenient prior; it is not part of the exact derivation above.

If sampling stops at \(t_{\min}\), its intended output law is \(p_{t_{\min}}\), not exactly \(p_0\). Applying a final posterior mean changes the output law again; it is not an exact substitute for the missing evolution. Evaluate separately:

  • terminal prior error: standard normal versus the actual \(p_1\);
  • numerical error: solver resolution at a fixed field;
  • estimation error: the learned field versus the exact field;
  • endpoint choice: \(p_{t_{\min}}\) versus clean data.

Part 6 implements these comparisons on a Gaussian mixture where the reference score is known.

Appendix A. Bayes optimality and a standalone derivation of Tweedie’s formula

Assume \(X\) has a finite second moment. Let \(m(y)=\mathbb E_{X\mid Y=y}[X]\). For any proposed estimate \(d\),

\[\begin{aligned} \mathbb E_{X\mid Y=y}[(X-d)^2] &=\mathbb E_{X\mid Y=y}[(X-m(y)+m(y)-d)^2]\\ &=\operatorname{Var}(X\mid Y=y)+(m(y)-d)^2. \end{aligned}\]

The cross term vanishes because \(\mathbb E_{X\mid Y=y}[X-m(y)]=0\). Hence \(d=m(y)\) minimizes conditional risk, and choosing this value at each \(y\) minimizes overall risk, obtained by averaging the conditional risk over \(Y\sim p_Y\). This is Bayes optimality for squared error; other losses can give other estimators.

Now write the Gaussian likelihood and marginal:

\[p(y\mid x)=\frac{1}{\sqrt{2\pi\sigma^2}} \exp\left[-\frac{(y-x)^2}{2\sigma^2}\right],\qquad p_Y(y)=\int p(y\mid x)p_X(x)\,dx.\]

Differentiate the likelihood:

\[\partial_y p(y\mid x)=\frac{x-y}{\sigma^2}p(y\mid x).\]

Differentiate the marginal and separate terms:

\[p_Y'(y)=\frac{1}{\sigma^2} \left[\int x\,p(y\mid x)p_X(x)\,dx-y\,p_Y(y)\right].\]

Bayes’ rule identifies the first integral as \(p_Y(y)\mathbb E_{X\mid Y=y}[X]\). Dividing by the positive noisy marginal gives

\[\partial_y\log p_Y(y)=\frac{\mathbb E_{X\mid Y=y}[X]-y}{\sigma^2}.\]

Rearrange to obtain the stated formula. For data without a density, replace \(p_X(x)dx\) by the probability measure of \(X\). For vectors and isotropic Gaussian noise, the same calculation uses a gradient and gives \(\mathbb E_{\mathbf X\mid\mathbf Y=\mathbf y}[\mathbf X]=\mathbf y+\sigma^2\nabla\log p_{\mathbf Y}(\mathbf y)\).

Appendix B. The regression decomposition

For a target \(U\), input \(A=(X_t,t)\), and regression function \(r(A)\), let \(m(A)=\mathbb E_{U\mid A}[U]\). Conditional expansion gives

\[\mathbb E_{U\mid A}[(r(A)-U)^2] =(r(A)-m(A))^2+\operatorname{Var}(U\mid A).\]

The expectation on the left is over the conditional law of \(U\) given the fixed input \(A\). Multiply by a time-dependent weight and average over \(A=(X_t,t)\): first draw \(t\) from the training-time distribution, then \(X_t\sim p_t\). Taking \(U\) to be the conditional corruption score makes \(m(A)\) the marginal score, which proves the loss decomposition in Section 3. The irreducible conditional variance is nonnegative; it need not be strictly positive for every possible data distribution.

Appendix C. Deriving the forward SDE and its training kernel

One forward step and its small-time limit

On a uniform grid \(t_k=kh\), set \(t=t_k\). Let \(h>0\) be a small step and choose the rate \(\beta(t)\ge0\). The forward update contracts each particle and adds independent Gaussian noise:

\[\boxed{X_{t+h}=\sqrt{1-\beta(t)h}\,X_t+ \sqrt{\beta(t)h}\,\varepsilon_k,\qquad \varepsilon_k\sim\mathcal N(0,1),\quad \beta(t)h<1.}\]

The noise draws are independent across steps and independent of the current particle. The one-step noise variance is \(\beta(t)h\); the one-step signal amplitude is \(\sqrt{1-\beta(t)h}\). Their squared coefficients add to one.

For a bounded continuous rate, expand the contraction as \(h\to0\):

\[\sqrt{1-\beta(t)h}=1-\tfrac12\beta(t)h+O(h^2).\]

Therefore, for a fixed current position,

\[X_{t+h}-X_t=-\tfrac12\beta(t)X_t h +\sqrt{\beta(t)}\,\sqrt h\,\varepsilon_k+O(h^2)X_t.\]

A Brownian increment \(\Delta W_k=W_{t+h}-W_t\) has distribution \(\mathcal N(0,h)\), so it can be represented by \(\sqrt h\,\varepsilon_k\). The leading terms are precisely the Euler–Maruyama discretization of

\[\boxed{dX_t=-\tfrac12\beta(t)X_t\,dt+\sqrt{\beta(t)}\,dW_t.}\]

Under the usual regularity conditions, the discrete process converges to this SDE as the mesh shrinks. Equivalently, its conditional mean increment divided by \(h\) tends to \(-\beta(t)x/2\), and its conditional increment variance divided by \(h\) tends to \(\beta(t)\). We do not divide Gaussian noise by \(h\) to obtain an ordinary derivative: Brownian motion has no ordinary velocity. This is the VP limit developed in Song et al.’s Appendix B, Eqs. (22)–(25).

Why the accumulated amplitude is determined by the rate

After \(k\) discrete steps of size \(h\), repeated substitution gives the cumulative multiplier

\[\alpha_{t_k}^{(h)}=\prod_{j=0}^{k-1}\sqrt{1-\beta(t_j)h}.\]

Conditional on \(X_0=x_0\), the chain is Gaussian: each step is a linear transformation of the previous Gaussian position plus independent Gaussian noise. Its conditional mean is \(\alpha_{t_k}^{(h)}x_0\). To find its conditional variance, define \(V_k=\operatorname{Var}(X_{t_k}\mid X_0=x_0)\), with \(V_0=0\). Independence of the new noise gives

\[\begin{aligned} V_{k+1}&=(1-\beta(t_k)h)V_k+\beta(t_k)h,\\ 1-V_{k+1}&=(1-\beta(t_k)h)(1-V_k). \end{aligned}\]

Iterating from \(1-V_0=1\) gives

\[1-V_k=\prod_{j=0}^{k-1}(1-\beta(t_j)h) =(\alpha_{t_k}^{(h)})^2.\]

Thus the accumulated conditional variance is \(V_k=1-(\alpha_{t_k}^{(h)})^2\). This is variance given the clean observation, not the marginal variance after averaging over the data.

Now hold a terminal time \(t\) fixed and take grids with \(h=t/k\to0\). For bounded \(\beta\), the expansion \(\log(1-\beta(t_j)h)=-\beta(t_j)h+O(h^2)\) has a uniform remainder. The sum of \(k\) remainders is \(O(kh^2)=O(h)\) at fixed \(t\), and therefore vanishes. Taking logarithms of the product gives

\[\log\alpha_{t_k}^{(h)}=\frac12\sum_{j=0}^{k-1}\log(1-\beta(t_j)h) \longrightarrow-\frac12\int_0^t\beta(u)\,du.\]

The Riemann sum converges for continuous \(\beta\). Hence \(\alpha_t^{(h)}\to\alpha_t\), and the conditional variance converges to \(1-\alpha_t^2\). At finite \(h\), the discrete multiplier \(\alpha_t^{(h)}\) generally differs from the exact continuous multiplier \(\alpha_t\); the exact transition stated in Section 1 avoids this discretization error.

Thus the continuous-time conditional law can be sampled in one operation:

\[\boxed{X_t=\alpha_tX_0+\sqrt{1-\alpha_t^2}\,\varepsilon, \qquad \alpha_t=\exp\!\left[-\frac12\int_0^t\beta(u)\,du\right], \quad\varepsilon\sim\mathcal N(0,1).}\]

Here the equality describes the conditional law at one selected time, with noise independent of \(X_0\). It does not specify a trajectory by reusing this one noise draw at every time. The final subsection below verifies the kernel directly from the SDE’s conditional moment equations.

Differentiating the cumulative multiplier gives the inverse relationship:

\[\boxed{\alpha_t'=-\tfrac12\beta(t)\alpha_t, \qquad\beta(t)=-2\frac{d}{dt}\log\alpha_t.}\]

The training-data schedule and the ODE rate are not independent choices. The same \(\beta(t)\) produces the noisy densities and appears in \(v(x,t)=-\beta(t)[x+s_t(x)]/2\). Data are at time zero; the standard Gaussian used at time one approximates the actual terminal law for a finite-rate schedule.

NoteRelating a discrete forward step to the continuous rate

For \(0\le u<t\le1\), the exact VP transition is

\[X_t\mid X_u=x\sim\mathcal N\!\left( \frac{\alpha_t}{\alpha_u}x,\ 1-\frac{\alpha_t^2}{\alpha_u^2}\right).\]

In discrete DDPM notation, a step’s noise variance \(\beta_i\) is related to the continuous rate by

\[\beta_i=1-\exp\!\left[-\int_{t_{i-1}}^{t_i}\beta(u)\,du\right] \approx\beta(t_{i-1})(t_i-t_{i-1}).\]

Our \(\alpha_{t_i}\) is the cumulative amplitude \(\sqrt{\prod_{j=1}^i(1-\beta_j)}\). It is not the one-step retention \(1-\beta_i\). One-step noise variance, accumulated noise variance, and continuous-time rate must not be interchanged.

Checking the conditional law directly from the SDE

Fix the clean value \(X_0=x_0\). For the forward SDE, let \(m_t\) and \(V_t\) be the conditional mean and variance. The linear drift and Gaussian Brownian increments give a Gaussian conditional law, with

\[m_t'=-\tfrac12\beta(t)m_t,\quad m_0=x_0, \qquad V_t'=-\beta(t)V_t+\beta(t),\quad V_0=0.\]

Solving the first equation gives \(m_t=\alpha_t x_0\). Since \(\frac{d}{dt}\alpha_t^2=-\beta(t)\alpha_t^2\), the function \(V_t=1-\alpha_t^2\) satisfies the second equation and its initial condition. Hence

\[X_t\mid X_0=x_0\sim\mathcal N(\alpha_t x_0,1-\alpha_t^2).\]

The coefficient of \(dW_t\) is \(\sqrt{\beta(t)}\), so its contribution to the variance equation is \(\beta(t)\). This is why using \(\beta(t)\) itself as the noise standard deviation would change the density path.

Finally, the forward Fokker–Planck equation is

\[\partial_t p_t=\frac{\beta(t)}2\partial_x(xp_t) +\frac{\beta(t)}2\partial_{xx}p_t =-\partial_x\!\left[p_t\left(-\frac{\beta(t)}2[x+s_t(x)]\right)\right].\]

Thus the same schedule that supplies the training pairs determines the probability-flow velocity. This is the VP specialization of the paper’s Eq. (13); the conditional kernel agrees with its Appendix B.

Part 6 provides a complete executed notebook that trains a small network and samples the two-component example.

Appendix D. An alternative proof using mixture components

D.1. A finite dataset becomes a Gaussian mixture after corruption

Let the observed clean values be \(x_1,\ldots,x_n\). Their empirical distribution is

\[\widehat P_0=\sum_{i=1}^n w_i\delta_{x_i},\qquad w_i\geq0,\quad\sum_iw_i=1,\]

where \(\delta_{x_i}\) denotes a point mass at \(x_i\) and usually \(w_i=1/n\). Select an index \(I\) with probability \(w_i\), then set \(X_0=x_I\). This is an exact representation of the empirical distribution, not a fitted Gaussian-mixture assumption about the population.

Fix a positive time. For this appendix, abbreviate the existing noise standard deviation by \(\sigma_t=\sqrt{1-\alpha_t^2}\). The forward corruption is

\[X_t=\alpha_tX_0+\sigma_t\varepsilon,\qquad \varepsilon\sim\mathcal N(0,1),\]

with noise independent of the selected clean observation. Thus

\[X_t\mid I=i\sim\mathcal N(\alpha_tx_i,\sigma_t^2),\qquad \boxed{\widehat p_t(x)=\sum_iw_i\mathcal N(x;\alpha_tx_i,\sigma_t^2).}\]

Each clean point produces one noisy Gaussian component. If the clean distribution is instead a mixture of Gaussians with nonzero component variances, those variances also contribute to the noisy component variances, as in Part 6.

D.2. Differentiate the mixture and identify the weights

Write \(\phi_i(x)=\mathcal N(x;\alpha_tx_i,\sigma_t^2)\). The component derivative is

\[\phi_i'(x)=\phi_i(x)\frac{\alpha_tx_i-x}{\sigma_t^2}.\]

Divide the derivative of the mixture by its density:

\[\begin{aligned} \widehat s_t(x) &=\frac{\widehat p_t'(x)}{\widehat p_t(x)}\\ &=\frac{\sum_iw_i\phi_i(x)(\alpha_tx_i-x)/\sigma_t^2} {\sum_jw_j\phi_j(x)}\\ &=\sum_i r_i(x,t)\frac{\alpha_tx_i-x}{\sigma_t^2}, \end{aligned}\]

where Bayes’ rule gives

\[\boxed{r_i(x,t)=\frac{w_i\phi_i(x)}{\sum_jw_j\phi_j(x)} =P(I=i\mid X_t=x).}\]

These probabilities sum to one. They depend on the observed noisy position, unlike the original weights \(w_i\). Consequently,

\[\boxed{\widehat s_t(x)=\mathbb E_{I\mid X_t=x} \left[\partial_x\log p_t(x\mid X_0=x_I)\right].}\]

The expectation is over the possible clean-data indices conditional on the fixed noisy input. The network receives \((x,t)\) because these features determine which clean origins are plausible. It does not receive the actual index used to construct a training pair.

D.3. The posterior mean and Tweedie’s formula

Collect the terms in the score expression:

\[\widehat s_t(x)=\frac{\alpha_t\sum_i r_i(x,t)x_i-x}{\sigma_t^2}.\]

Under the empirical data distribution,

\[m_t(x):=\mathbb E_{\widehat P_0}[X_0\mid X_t=x] =\sum_i r_i(x,t)x_i.\]

Therefore, for \(\alpha_t>0\),

\[\boxed{m_t(x)=\frac{x+\sigma_t^2\widehat s_t(x)}{\alpha_t}.}\]

This is the VP form of Tweedie’s formula. To see its Bayes-optimal meaning, let \(a\) be a proposed clean reconstruction. At the fixed noisy input,

\[\mathbb E_{\widehat P_0}[(X_0-a)^2\mid X_t=x] =\operatorname{Var}_{\widehat P_0}(X_0\mid X_t=x)+(m_t(x)-a)^2.\]

Only the second term depends on \(a\), so the posterior mean is the squared-error-optimal denoiser. This does not make a posterior mean a posterior sample.

D.4. A zero conditional score and a nonzero marginal score

Take equally weighted clean points \(x_1=0\) and \(x_2=2\), and evaluate at noisy position \(x=0\). Assume \(\alpha_t>0\) and \(\sigma_t>0\). Their conditional scores are

\[\left.\partial_x\log p_t(x\mid X_0=0)\right|_{x=0}=0, \qquad \left.\partial_x\log p_t(x\mid X_0=2)\right|_{x=0} =\frac{2\alpha_t}{\sigma_t^2}.\]

The posterior probability of the second clean point is

\[r_2(0,t)=\frac{\exp(-2\alpha_t^2/\sigma_t^2)} {1+\exp(-2\alpha_t^2/\sigma_t^2)}>0.\]

Hence

\[\boxed{\widehat s_t(0)=r_2(0,t)\frac{2\alpha_t}{\sigma_t^2}>0.}\]

The first clean point with zero corruption noise has a zero target, but the optimal prediction at that noisy input is positive. The second clean point remains a possible origin and contributes a positive conditional score. The calculation evaluates continuous score functions at a point; the distinction persists in nearby intervals, which have positive probability. It never asserts that an average of identically zero targets is nonzero.

D.5. From a finite mixture to an arbitrary population

For an arbitrary clean probability distribution \(P_0\), replace the sum by an integral with respect to that distribution:

\[p_t(x)=\int\mathcal N(x;\alpha_tu,\sigma_t^2)\,dP_0(u).\]

This is a continuous location mixture after corruption. The clean law may be discrete, continuous, or mixed; it need not have a density. No informal limit of an infinitely large dataset is required.

Differentiating the Gaussian kernel under the integral and dividing by \(p_t(x)\) gives

\[\begin{aligned} s_t(x) &=\int\frac{\alpha_tu-x}{\sigma_t^2} \frac{\mathcal N(x;\alpha_tu,\sigma_t^2)}{p_t(x)}\,dP_0(u)\\ &=\mathbb E_{X_0\mid X_t=x} \left[\frac{\alpha_tX_0-x}{\sigma_t^2}\right]. \end{aligned}\]

The measure multiplying the component score is precisely the posterior distribution of \(X_0\) given \(X_t=x\). At positive noise and \(\alpha_t>0\), the Gaussian kernel and its spatial derivative are bounded as functions of the clean location, locally uniformly in \(x\), which justifies this differentiation. For a global squared-error denoising risk, assume \(\mathbb E_{X_0\sim P_0}[X_0^2]<\infty\).

Rearranging yields the population Tweedie identity. The exact empirical-score transport approaches the discrete training distribution as the noise tends to zero. Model restrictions and regularization may help generalization, but do not guarantee it. A finite-data regression learns the score of the corrupted empirical distribution in its unrestricted optimum; approximating the population score additionally involves finite-data, model, and optimization errors.

For the finite mixture, the posterior weights can actually be evaluated by summing over the dataset. This offers an exact empirical-score reference at positive time, but costs a sum over all \(n\) observations per query. Neural regression approximates that function without enumerating the dataset during each sampling step. Training itself continues to use forward-generated pairs; it does not require calculating these posterior weights.

D.6. Local density information and trajectory history

A local derivative that reflects the originating distribution. The score \(s_t(x)=\partial_x\log p_t(x)\) describes the local spatial slope of the current log density. Yet that density combines contributions from the clean-data distribution:

\[p_t(x)=\int p_t(x\mid x_0)\,p_{\mathrm{data}}(x_0)\,dx_0.\]

Its local slope therefore reflects the possible clean origins and the forward corruption law. This is dependence on the originating distribution, not memory of an individual particle’s trajectory. Different histories that produce the same current density \(p_t\) give the same score at that time.

Once the time-dependent score field is specified, the sampler evaluates it using only the current position and time. The probability-flow ODE needs no stored trajectory history. The reverse SDE discussed in Part 2 is likewise a time-inhomogeneous Markov process. Posterior averaging over possible clean origins does not change this property.

For exact empirical-score sampling without a neural network, including scalar and MNIST experiments, see Part 07 · Empirical-score sampling.