Score-based generative model learn manifold-like structures with constrained mixing
Abstract
How do score-based generative models (SBMs) learn the data distribution supported on a low-dimensional manifold?
We investigate the score model of a trained SBM through its linear approximations and subspaces spanned by local feature vectors.
During diffusion as the noise decreases, the local dimensionality increases and becomes more varied between different sample sequences.
Importantly, we find that the learned vector field mixes samples by a non-conservative field within the manifold, although it denoises with normal projections as if there is an energy function in off-manifold directions.
At each noise level, the subspace spanned by the local features overlap with an effective density function.
These observations suggest that SBMs can flexibly mix samples with the learned score field while carefully maintaining a manifold-like structure of the data distribution
Introduction
[Figure]
Score-based generative models (SBM) have achieved great success in learning natural data distributions [7, 8], which according to the manifold hypothesis are supported on low-dimensional manifolds.
Unlike decoder-based methods such as VAEs and GANs, most SBMs do not explicitly construct distributions on low-dimensional manifolds with a compressed representation.
Then, how do SBMs approximate distributions on manifold?
Given a dataset { x ( i ) } drawn i.i.d.
from an unknown data density q 0 on R d , a score model g σ t ( · ) : R d → R d estimates the score function of the noisy data distribution ∇ x log q σ t ( x ) , where σ t is the standard deviation of the additive Gaussian noise at time t , and t ∈ [0 , 1] .
Typically, as t decreases, σ t decreases towards zero, and q 1 ( x ) is almost identical to a Gaussian.
The estimated score function can then be used to define a stochastic or deterministic process to generate samples close to q 0 ( x ) by initialising from Gaussian samples.
This procedure forms the basic methodology of SBM.
Fig.
1 summarises our main finding.
The left two panels are two rotated views of the example data density q {+
 (blue-orange)+} on a 2D manifold in a 3D ambient space.
The density implies a conserved vector field. The right two panels show the vector field of a score model g which approximates the score of q 0 but is not guaranteed to be conservative.
We find that, in this score model, the vector field is non-conservative only within the manifold; whereas the field in directions normal to the manifold remains close to the conservative score field of the noisy data distribution, constraining the samples to stay around the data manifold.
Further, the local features of g span the same local subspace of an effective density function that is consistent with g in the sense we clarify soon.
Local orthogonal features of approximate score functions
A local approximation of the score g σ ( x ) ≈ g σ ( x 0 ) + ∇ x g σ ( x ) | x 0 ( x − x 0 ) around x 0 involves the score Jacobian, so we use its singular value decomposition (SVD) to analyse g σ locally:
[Equation]
where the features u i ( x ) , v i ( x ) and s i ( x ) ≥ 0 are, respectively, the i ’th left singular vector, right singular vector, and singular value of ∇ x g σ ( x ) , ordered so that s i <
s j for i < j .
If g σ is the score of a density function, then g σ is conservative, ∇ x g σ ( x ) is symmetric (or normal), and u i = ± v i for all i .
To build more intuitions about score Jacobians, consider the multivariate Gaussian N ( x ; µ, Σ) which has a constant score Jacobian − Σ − 1 .
Each pair of its singular vectors have opposite signs .
In particular, the singular value of rank i is equal to the inverse variance along the i ’th singular vector.
Now, suppose that the data distribution q 0 is a low-dimensional Gaussian supported on a subspace of R d .
After adding a small additive Gaussian noise on R d , the SVD of the score Jacobian shows interpretable properties of the data distribution: large singular values or small variances appear along directions with abrupt changes in the score, reflecting steep curvatures along the off-manifold directions.
Conversely, small singular values or large variances are associated with on-manifold directions along which the data density varies smoothly.
This pattern generalises to curved manifolds as long as the noise is small compared to the local curvature.
In practice, the Jacobian of a learned score estimator ∇ x g σ ( x ) may not be symmetric as that of the Gaussian, but we can compare it to an effective conservative (energy-based) score field.
Proposition 1.
Given a model score g σ t ( x ) , there exists a conservative field ˜ g
σ t ( x ) such that for every path x 1: t from g σ t , the likelihood of x t computed under g σ t and ˜ g σ t are identical.
Proof.
Suppressing the subscripts for brevity, we decompose ∇ g as the sum of a symmetric component ∇ ˜
g :
= 0 .
5( ∇ g + ∇ ⊺ g ) and a skew-symmetric component H := 0 .
5( ∇ g − ∇ ⊺ g ) .
By Poincaré’s
Lemma, the symmetric ∇ ˜ g implies the existence of a conservative field ˜ g .
Given a sample path x 1: t , the likelihood of x t depends on g through its divergence or the trace of the score Jacobian Tr( ∇ ˜ g ) [7, eqn. 39].
Then, we have Tr( ∇ g ) =
Tr( ∇ ˜ g + H ) =
Tr( ∇ ˜ g )+
Tr( H ) =
Tr( ∇ ˜ g )+0 =
Tr( ∇ ˜ g ) .
This means that, given a sample path , ˜ g σ is a valid score of an (unknown) density function equivalent to g σ in terms of x t ’s likelihood.
Similar to but unlike the SVD of ∇ x g σ ( x ) , the eigendecomposition of the symmetric ∇ x ˜ g σ ( x ) reveals the local features of the equivalent density: following the intuition of the Gaussian distributions, we see that the eigenvectors with negatively large eigenvalues correspond to off-manifold directions ( − Σ − 1 is negative semi-definite); eigenvectors with small-inmagnitude eigenvalues indicate on-manifold directions.
Positively large eigenvalues indicate positive curvature, and we find that they exhibit on-manifold features as shown in our experiments.
Experiments
We now empirically compare the SVD of ∇ x g σ ( x ) and the eigendecomposition of ∇ x ˜ g σ ( x ) to discover local geometries of a learned score model.
For ease of visualisation, we used an SBM trained on MNIST digits [4], so d = 28 × 28 = 784 .
The model is based on a U-net, adapted from the model of Song et al.
More details are in Appendix A. For a given generated x at noise level σ , we denote the (minor) left and right singular vectors corresponding to the smallest singular value of ∇ x g σ ( x ) as u − and v − , respectively, and the (major) vectors to the largest singular value as u + and v + .
For the “symmetrised” score ∇ x ˜ g σ ( x ) , we denote the minor and major eigenvectors as w − and w + , respectively, and the eigenvector with smallest-in-magnitude eigenvalue as w 0 .
3.1 Local principal directions
Fig.
2 shows the generated samples at five time steps in the first column and their feature vectors in the other columns.
Vectors v − , u − and w 0 reflect more general distortions of the strokes at higher noise levels, and more localised changes at lower noise levels.
However, u − and v − are not well aligned, reflecting non-conservation of the score model, or a non-normal score Jacobian.
The eigenvectors w 0 and w + of the symmetrised Jacobian show similar on-manifold semantics, but they are also not aligned with the singular vectors.
Major vector u + and v + show high-frequency contents in the
[Figure]
u v u + v +
[Figure]
w
[Figure] [Figure]
background, which are likely off-manifold directions, as following these directions makes a sample less realistic.
Unlike the minor singular vectors, these major vectors differ by a sign and points towards opposite directions.
The eigenvector w − of the effective energy-based field also shows high-frequency, off-manifold patterns in the background, similar to the major singular vectors.
In Fig.
3 (top) [Figure] we show the inner products
u i ( x ) · v i ( x ) (cosine angle) for three other example image sequences and the summary statistics of 128 images.
They confirm that the singular vectors are not aligned for lower ranks and they differ by a sign for higher ranks.
The opposite signs between u i ’s and v i ’s in higher ranks are consistent with the Gaussian score along off-manifold directions.
But how to interpret the misalignment at lower ranks?
The example image at t = 0 .
3 in Fig.
2 gives an interesting clue: its v − focuses on the outline of the digit 5 but then maps to a u − that resembles the outline of 6.
This misalignment of singular vectors mixes data across different components, and we speculate that it could facilitate mixing between high-level image classes at high noise levels.
3.2 Singular values reveal a progressive and diverse manifold expansion
Following from our Gaussian intuition, the inverse singular values of a score Jacobian are related to the local length scales along principal directions of the distribution.
We should then expect to see inverse singular values equal to the corresponding noise variances σ 2 t along many potentially off-manifold directions.
The examples in Fig.
3 (bottom left) support this prediction.
In addition,
[Figure]
u
[Figure]
v
[Figure]
u [Figure] [Figure] v , w n the noise variance σ 2 t lower bounds the inverse singular values, because the smoothing effect of the
Gaussian noise determines the smallest length scale.
All nontrivial inverse singular vectors above the noise levels contribute to local data dimensionality, so we estimated the local data dimensionality of x t by the smallest r t such that s − 1 i ( x t ) <
(1 + κ ) σ 2 t for all i > r t , where we set κ = 0 .
1 as a slack constant.
The coloured dots in Fig.
3 (bottom left) show the estimated local dimensionality for three images at each t , and Fig.
3 (bottom right) shows the distribution of thus estimated local dimensionalities for 128 images: they increases and spreads out more with decreasing noise levels.
We compared this with the local dimensionality estimated by a VAE model [3, 2], described in Appendix B.
The VAE-estimated local dimensionality of clean images turned out to be within 13 ± 3 , substantially lower and less varied than the estimates from the score model in Fig.
Thus, these patterns of singular values suggest that the SBM has a much more expressive and more flexible representation power than the VAE.
3.3 Misaligned singular vectors span the same subspace and provides non-normal mixing.
From Figs.
2 and 3, we see that the singular vectors and eigenvectors are misaligned in the subspace given by nontrivial singular values.
In principle, the right singular vectors define an input space of local changes, and the left singular vectors define an output basis to apply the denoising vector.
To at least preserve mixing during diffusion, the left and right subspaces spanned by nontrivial u i and v i must substantially overlap, since otherwise the score field can project data into off-manifold directions.
Further, they should also overlap with the eigen-subspace of the effective energy-based density spanned by { w i } with small-in-magnitude eigenvalues.
We quantify the amount of overlap between these subspaces by how well one reconstructs the other for the first n vectors:
[Equation]
This is a criterion based on explained variance—a larger value indicates a better overlap.
The results in Fig.
4 confirm a considerable overlap between the three subspaces within the nontrivial ranks at each t (Fig. 3).
Therefore, although g σ ( x ) mixes image features onto different components in a non-normal fashion, it still updates the image within highly overlapped subspaces.
The singular subspaces of ∇ x g σ ( x ) also overlap well with the eigen-subspace of the symmetrised ∇ x ˆ g σ ( x ) , suggesting that the learned singular subspaces conform to the data subspace of the effective density.
Conclusion
We have shown that the score field of a trained score-based model shows low local dimensionality consistent with the manifold hypothesis.
As the noise scale decreases, the modelled manifold dimensionality rises and becomes more varied, reflecting increasingly precise description of samples.
In addition to projecting noisy, off-manifold components back onto the manifold by normal projections, the score function mixes between feature directions within the data manifold using a non-conservative field, giving misaligned singular vectors.
Nonetheless, these vectors span overlapping input and output subspaces, both of which also overlap with the local eigen-subspace of the effective energybased field.
Therefore, the score-based generative model learns a vector field that carefully constrains the samples to be within the manifold while mixing samples within the manifold.
This explains the well-known harmless effect of non-conservation [6] and the little improvement obtained by encouraging conservation Acknowledgement We thank Conor Durkan, Mikołaj Bi´nkowski, Wendy Shang and Sander Dieleman for sharing their implementation of the diffusion model.
A The score-based model
The model, training objectives and procedures are essentially the same as the one proposed by [8].
A.1 Denoising networks
We took a standard implementation of the Unet and reduces the input size to 28 × 28 × 1 .
The batch size is 2 048 and the learning rate is 0 . 0003 .
We trained the model for 540 000 steps.
A.2 Diffusion process
After obtaining the score estimates, we generated the images by discretising the SDE by the EulerMaruyama method.
The noise schedule is a monotically decreasing function of t , and we apply appropriate scaling on the drift term of the SDE (variance-preserving).
We took samples at five noise levels at t ∈ { 0 . 01 , 0 . 03 , 0 . 05 , 0 . 15 , 0 . 3 } , approximately corresponding to noises with standard deviations σ t ∈ { 0 . 039 , 0 .
For all summary statistics we used 128 randomly sampled images from the model so that they stay in the learned but approximate score field.
Using more images does not change the conclusions.
B VAE model
Following [3, 2], we estimated the local dimensionality of a data point by the number of latent dimensions in which the posterior variances were close to zero.
In practice, we regarded any posterior variance less than 0.5 as being close to zero.
The VAE model we used to obtain a baseline data dimensionality has a standard Gaussian prior on R 100 .
The likelihood is a Gaussian with its mean given by a neural network function of the latent variable and with variance as a free positive parameter.
The variational posterior is a factorised Gaussian with means and variances as output of a neural network function.
All neural networks have convolutional, ReLU nonlinearity and batch normalisation layers similar to the DCGAN.
We trained the network for 1 000 epochs on 60 000 MNIST digits.
The estimated local dimensionality varies between digits: the digit “1” in general has lower dimensionality (around 11) than the other digit (around 18).
This number decreases when we trained on noisy images, consistent with the effect of noise smoothing.
C Related work
Mohan et al.
[5] used SVD to analyse locally linear features of the trained denoising model which was not used for diffusion-based generation.
There, the trained model f ( · ) : R d → R d outputs the denoised image under the expected l -2 loss directly rather than the score function.
Also, the networks are constrained to be bias-free and have ReLU nonlinearities, so that the network is locally affine: f ( x ) = ∇ f ( x ) x .
We kept our score network to be as general as possible so did not impose these constraints.
If we adopt these constraints, we will have g ( x ) =
∇ g ( x ) x .
Under Gaussian noise with variance σ 2 , when both f and g are perfectly trained, the optimally (in terms of expected l -2 loss) denoised estimate is
[Equation]
a form of the Stein’s unbiased risk estimate.
Clearly, the f used by Mohan et al.
[5] and the g used by us are equivalent parametrisations of each other.
One should then expect to find the same conclusions between this paper and theirs.
A seemingly contradictory finding is that, in Mohan et al.
[5], the left and right singular vector of ∇ f ( x ) at a given rank were mostly aligned , whereas those of ∇ g ( x ) here are mostly opposite to each other.
This is, however, expected.
In the idealised case where the score function is perfectly estimated, ∇ g is symmetric, and so is ∇ f .
For small noise, the score Jacobian ∇ g is symmetric with eigenvalues lowerbounded by − 1 /σ 2 , since this is the lowest noise present in the data.
Applying the tranformation between f and g in (3) shows that ∇ f is in fact positive semidefinite, which has identical left and right singular vectors.
However, Mohan et al.
[5] did not interpret the misaligned singular vectors, which we explain as arising from the non-conservation of the approximate score model.