liveBook · Manning

Chapter 14: Latent space and generative modeling, autoencoders, and variational autoencoders

What you will learn in chapter 14 of Math and Architectures of Deep Learning

This introduction defines latent vectors as learned, compact representations of observed inputs that retain goal-relevant information while discarding the rest.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction defines latent vectors as learned, compact representations of observed inputs that retain goal-relevant information while discarding the rest.

Key terms: latent vector, latent space, embedding, observed vector, input vector, mapping, dimensionality reduction, encoding, neural network, information loss

14.1 Geometric view of latent spaces

This section presents latent-space modeling as learning a manifold for inputs with a property of interest and projecting inputs onto it as compact, lossy embeddings.

Key terms: input space, manifold, cluster, property of interest, non-uniform distribution, low entropy, latent space modeling, latent vector, embedding, projection

14.2 Generative classifiers

This section contrasts discriminative classifiers with generative classifiers, explaining how probability-based data-distribution modeling can improve insight, reduce overfitting, and generate new class instances.

Key terms: discriminative classifiers, generative models, latent space models, threshold, probability, manifolds, decision boundaries, probability density functions, overfits, training data

14.3 Benefits and applications of latent-space modeling

This section explains how latent-space modeling removes irrelevant information, makes tasks such as classification and similarity comparison easier, and supports generation, compression, and denoising.

Key terms: latent-space modeling, latent vector, discriminative information, redundant information, noise, latent subspace, latent space, Cartesian coordinates, polar coordinates, decision boundary

14.4 Linear latent space manifolds and PCA

This section recaps PCA as a linear latent-space method that centers data, retains high-variance principal directions, and reconstructs from a lower-dimensional projection with minimal linear reconstruction loss.

Key terms: PCA, principal value, principal vector, principal component, maximum variance, orthogonal direction, low variation, smallest principal value, dimensionality reduction, reconstruction loss

14.4.1 PyTorch code for dimensionality reduction using PCA

This subsection demonstrates PyTorch PCA dimensionality reduction of 3D data and approximate reconstruction from its lower-dimensional representation.

Key terms: PCA, dimensionality reduction, projection, lower-dimensional space, reconstruction, data matrix

14.5 Autoencoders

This section introduces autoencoders as unsupervised encoder-decoder networks that learn compact latent representations by reconstructing their inputs.

Key terms: autoencoder, encoder, decoder, latent vector, reconstructed input, latent space, reconstruction loss, end-to-end, unsupervised, representation learning

14.5.1 Autoencoders and PCA

This subsection contrasts PCA’s linear dimensionality reduction with the potentially nonlinear dimensionality reduction performed by autoencoders.

Key terms: PCA, autoencoder, dimensionality reduction, best-fit hyperplanes, nonlinear hypersurfaces, encoder-decoder pair, single linear layer, ReLU, nonlinearity, hyperplane

14.6 Smoothness, continuity, and regularization of latent spaces

This section explains why reconstruction loss alone can produce distorted latent manifolds and how regularization, especially a Gaussian KL penalty, promotes smooth, compact latent spaces.

Key terms: reconstruction loss, latent space, latent-space manifold, encoder-decoder, smoothness, continuity, regularized latent space, unregularized latent space, regularization, KL divergence

14.7 Variational autoencoders

This section introduces variational autoencoders as autoencoders with an encoder–decoder architecture, reconstruction loss, and an additional KL divergence loss.

Key terms: variational autoencoder, VAE, autoencoder, encode, decode, input vector

14.7.1 Geometric overview of VAEs

This section gives a geometric account of how a variational autoencoder encodes an input as a sampled latent distribution and decodes it into a reconstruction.

Key terms: encoder, latent-space representation, latent-space map, stochastic mapping, Gaussian distribution, mean, narrow-peakedness, probability density function, small variance, small covariance

14.7.2 VAE training, losses, and inferencing

This section explains how a variational autoencoder trains an encoder and decoder with reconstruction and KL-divergence losses, and how its encoder produces latent representations at inference time.

Key terms: q(z|x), encoder, decoder, latent vector, Gaussian, reconstructed input, reconstruction loss, KL divergence loss, KLD loss, p(z)

14.7.3 VAEs and Bayes’ theorem

This subsection connects the encoder, decoder, and latent distribution in a VAE to posterior inference and Bayes’ theorem.

Key terms: encoder, stochastic mapping, q(z|x), posterior probability, p(z|x), KL divergence, decoder, latent-space point, reconstructed input, x̃

14.7.4 Stochastic mapping leads to latent-space smoothness

This subsection explains how stochastic encoder sampling makes a VAE latent space smooth by requiring nearby sampled latent points to decode to the same input region.

Key terms: stochastic mapping, encoder output, latent space, input space, smoothness, deterministic mapping

14.7.5 Direct minimization of the posterior requires prohibitively expensive normalization

This section explains why directly maximizing a VAE's posterior over latent space is computationally intractable and motivates ELBO-based training instead.

Key terms: posterior probability, latent space, training data, batch, normalization, latent vectors, iteration, epoch, O(n)

14.7.6 ELBO and VAEs

This section derives the evidence lower bound (ELBO) and shows that training a variational autoencoder means maximizing it through reconstruction quality and prior-based latent-space regularization.

Key terms: true posterior p(z|x), approximate posterior q(z|x), KL divergence, evidence log-likelihood, ELBO, evidence lower bound, expected log likelihood, reconstruction loss, KL regularization, prior p(z)

14.7.7 Choice of prior: Zero-mean, unit-covariance Gaussian

This section explains why VAEs commonly use a zero-mean, unit-covariance Gaussian prior and how its KL term constrains a diagonal-Gaussian latent posterior.

Key terms: zero-mean, unit-covariance Gaussian, N(0, I), identity matrix, known prior, latent space, KL divergence, unit ball, hypersphere, regularized latent space, minimum descriptor length

14.7.8 Reparameterization trick

This section explains how the reparameterization trick permits VAE training by backpropagation and contrasts the unconstrained autoencoder latent space with the regularized VAE latent space on MNIST.

Key terms: reparameterization trick, backpropagation, Gaussian, mean, variance, standard normal distribution, multivariate Gaussian, N(0,I), covariance matrix, Sigma

14.8 Summary

This summary recaps how latent-space models compress data around a property of interest and how PCA, autoencoders, and VAEs construct increasingly flexible and regular latent representations.

Concepts explained in this chapter

← Chapter 13: Fully Bayes model parameter estimation

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.