Latent Space Oddity: on the Curvature of Deep Generative Models

Georgios Arvanitidis, Lars Kai Hansen, Søren Hauberg · DOI

Abstract

Deep generative models provide a systematic way to learn nonlinear data distributions, through a set of latent variables and a nonlinear "generator" function that maps latent points into the input space. The nonlinearity of the generator imply that the latent space gives a distorted view of the input space. Under mild conditions, we show that this distortion can be characterized by a stochastic Riemannian metric, and demonstrate that distances and interpolants are significantly improved under this metric. This in turn improves probability distributions, sampling algorithms and clustering in the latent space. Our geometric analysis further reveals that current generators provide poor variance estimates and we propose a new generator architecture with vastly improved variance estimates. Results are demonstrated on convolutional and fully connected variational autoencoders, but the formalism easily generalize to other deep generative models.

The Problem: The Euclidean Lie

When training Variational Autoencoders (VAEs) or GANs, we typically treat the low-dimensional latent space as a flat Euclidean plane. We assume that a straight line between two points represents the most natural interpolation and that the $L_2$ distance accurately reflects similarity.

However, the generator function is highly nonlinear. This nonlinearity warps the space, acting like a funhouse mirror that stretches some regions and compresses others. Consequently, Euclidean distances in latent space are often semantically meaningless. Two points that appear close may be very different in the actual data manifold, while distant points might be nearly identical.

Euclidean distance in latent space fails to capture semantic similarity. Points A and B (both '0's) are further apart than B and C ('0' and '1') in Euclidean terms, despite A and B being more similar.

Methods: Latent Space as a Riemannian Manifold

The authors propose a shift in perspective: treating the latent space not as a flat plane, but as a Riemannian manifold. By deriving a local metric tensor $M_z$, we can mathematically characterize the distortion at any point $z$ in the latent space.

The Metric Tensor and Geodesics

For a stochastic generator (like a VAE) with mean $\mu$ and variance $\sigma$, the metric is defined by the Jacobians of these functions: $$M_z = J_\mu^T J_\mu + J_\sigma^T J_\sigma$$ This metric allows us to compute geodesics—the shortest paths along the curved manifold—rather than relying on straight Euclidean lines. These paths are found by solving a system of ordinary differential equations (ODEs).

The "Wall of Variance"

A critical discovery was that standard VAEs provide poor variance estimates in regions lacking training data. To fix this, the authors introduced a generator architecture using Radial Basis Function (RBF) networks for the variance. This ensures that uncertainty increases as one moves away from the data, effectively creating a "wall of variance" that forces geodesics and random walks to stay within the learned data manifold.

A comprehensive comparison showing how Riemannian geodesics (green) stay within high-density regions of the latent space and follow the data manifold in the input space, whereas Euclidean paths (red) cut through low-density "garbage" regions.

Key Results

  • Improved Clustering: On MNIST, using the Riemannian metric for $k$-means clustering improved accuracy from 77.57% (Euclidean) to 94.28%.
  • Natural Interpolation: Riemannian interpolants avoid the "abrupt" jumps seen in Euclidean paths, providing smoother transitions between generated images.
  • Robust Sampling: Random walks using the Riemannian metric stay "on-manifold," generating recognizable images for significantly longer sequences compared to Euclidean walks which quickly drift into nonsense.
  • Better Likelihoods: The RBF-based variance model significantly improved test log-marginal likelihoods on MNIST (from -68.25 to -50.34).

Conclusion

By acknowledging the inherent curvature of deep generative models, we can navigate latent spaces more effectively. The Riemannian framework provides an intrinsic way to measure distance and interpolate, leading to models that are more semantically consistent and robust to the distortions of nonlinear mapping.

Summary updated

BibTeX
@inproceedings{arvanitidis2018latent,
  author = {Georgios Arvanitidis and Lars Kai Hansen and Søren Hauberg},
  title = {{Latent Space Oddity: on the Curvature of Deep Generative Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2018},
  url = {https://openreview.net/forum?id=SJzRZ-WCZ},
}
Figure