Tutorial on Variational Autoencoders

Carl DoerscharXiv 2016

Abstract

Variational Autoencoders (VAEs) provide a mathematically principled way to perform unsupervised learning and generative modeling using standard neural networks. By combining Bayesian inference with the "reparameterization trick," VAEs allow us to model complex, high-dimensional data distributions and generate new, realistic samples using simple backpropagation. This tutorial summary explores the core mechanics of VAEs, their theoretical underpinnings, and their practical application to structured prediction tasks.

Introduction

The fundamental goal of generative modeling is to learn a probability distribution $P(X)$ over a dataset, such as images, to enable the generation of novel, realistic samples. Historically, this task faced significant hurdles: rigid model structures that failed to capture real-world complexity, the intractability of calculating likelihoods involving latent variables, and the high computational cost of iterative methods like Markov Chain Monte Carlo (MCMC). VAEs address these challenges by reframing statistical inference as a differentiable optimization problem.

The VAE Framework

VAEs operate on the assumption that observed data $X$ is generated from hidden, lower-dimensional latent variables $z$. While the true nature of $z$ is unknown, we assume it follows a simple prior distribution, typically a Gaussian $\mathcal{N}(0, I)$.

The graphical model of a VAE, illustrating the relationship between latent variables $z$, observed data $X$, and model parameters $\theta$.

The Evidence Lower Bound (ELBO)

Since direct maximization of the likelihood $P(X)$ is often impossible, VAEs maximize the Evidence Lower Bound (ELBO). The ELBO objective consists of two primary terms:

  1. Reconstruction Loss: Measures the model's ability to reconstruct the input $X$ from its latent representation $z$.
  2. KL Divergence: Acts as a regularizer, forcing the learned approximate posterior $Q(z|X)$ to remain close to the prior $P(z)$.

The Reparameterization Trick

A critical innovation in VAEs is the reparameterization trick. Standard backpropagation cannot pass through stochastic sampling steps. By expressing $z$ as a deterministic function of the model parameters and an independent noise source (e.g., $z = \mu + \sigma \odot \epsilon$, where $\epsilon \sim \mathcal{N}(0, I)$), the entire network becomes end-to-end differentiable.

Mapping Simplicity to Complexity

A core insight of the VAE framework is that a sufficiently expressive neural network can map a simple distribution to an arbitrarily complex one. This justifies the use of a simple Gaussian prior for $z$; the decoder network learns the complex transformation required to map these latent coordinates to the data manifold.

Illustration of mapping a simple Gaussian distribution (left) to a more complex, structured data manifold (right).

Results and Applications

The VAE framework has been extensively validated on the MNIST dataset of handwritten digits. The model successfully learns to generate recognizable digits from noise. Furthermore, Conditional VAEs (CVAEs) extend this by conditioning the model on specific inputs, enabling structured prediction. For instance, a CVAE can complete the missing half of a digit, producing multiple distinct and plausible completions where standard regression would yield a single blurry average.

Discussion and Limitations

Despite their theoretical elegance, VAEs are known for producing "blurry" samples compared to Generative Adversarial Networks (GANs). This is often attributed to the use of pixel-wise Euclidean distance in the reconstruction loss, which does not perfectly capture human visual perception. Additionally, while VAEs are robust, optimizing models with excessively large latent spaces can be challenging for stochastic gradient descent. Future work continues to explore more sophisticated loss functions and theoretical extensions to higher-dimensional proofs.

Summary updated

BibTeX
@misc{doersch2016tutorial,
  author = {Carl Doersch},
  title = {{Tutorial on Variational Autoencoders}},
  year = {2016},
  eprint = {1606.05908},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1606.05908},
}
Figure