Specialty Digest

Global English editionLearners’ Study Dashboard — in development
The Knowledge Library for All

Variational Autoencoder

nounDeep Learning and Neural Networksalso VAE, variational auto-encoder

In one line

A variational autoencoder is a generative neural network that learns to compress data into a smooth probabilistic latent space and to generate new samples by decoding points from that space.

A variational autoencoder, or VAE, is a type of generative neural network that learns to compress data into a compact, smooth representation, called the latent space, and to generate new data by decoding points from that space. Like an ordinary autoencoder, it has an encoder and a decoder, but instead of encoding each input as a single point, it encodes it as a probability distribution. This small change gives the latent space an orderly structure, so that picking a random point and decoding it yields a plausible new example. VAEs were introduced in 2013 and are a foundation of modern generative AI.

Autoencoders in brief

An autoencoder is a network trained to copy its input to its output through a bottleneck. The encoder compresses the input into a small vector, and the decoder tries to rebuild the original from it. Because the bottleneck is narrow, the network must learn the most important features of the data. Plain autoencoders are useful for compression, noise removal and dimensionality reduction, but their latent spaces are irregular. Points between known examples may decode to nonsense, so they are poor at generating new data.

How a VAE works

A VAE modifies the autoencoder in two ways. First, the encoder outputs two vectors for each input, a mean and a variance, which define a Gaussian distribution over the latent variables. Second, a latent vector is sampled from this distribution and passed to the decoder, which reconstructs the input. During generation, the encoder is not needed. One samples a latent vector from a standard normal distribution and decodes it to produce a new example.

Training uses a loss with two terms, which together form the evidence lower bound, or ELBO.

  • Reconstruction term: measures how well the decoder rebuilds the input, such as the pixel error for images.
  • Regularization term: the Kullback-Leibler divergence between the encoder’s distribution and a standard normal prior. It pushes the latent distributions toward a common, well-behaved shape, so the space is continuous and has no large gaps.

The balance between the terms controls the trade-off between sharp reconstructions and a smooth latent space. Beta-VAE puts extra weight on the regularization term to encourage more independent, interpretable factors.

The reparameterization trick

Sampling is a random operation, and gradients cannot flow backward through randomness, which would block backpropagation. Kingma and Welling’s key technical idea was the reparameterization trick. Instead of sampling the latent variable directly, the network samples noise from a standard normal distribution and computes the latent vector as the mean plus the standard deviation times the noise. Now the randomness is an input, and the path from the encoder’s outputs to the loss is differentiable, so ordinary gradient-based training works.

The latent space

The smooth latent space of a VAE has useful properties. Nearby points decode to similar outputs, so moving gradually from one point to another produces a smooth transformation, such as one face morphing into another. Directions in the space can correspond to meaningful attributes, such as smile, age or rotation, which allows editing by moving along a direction. Interpolating between two encoded inputs creates plausible intermediate examples. These properties make VAEs useful for exploration and design.

Variants of VAEs

  • Conditional VAE: adds a label or other condition to the encoder and decoder, so one can generate a requested class.
  • Beta-VAE: weights the regularization term more to promote disentangled factors.
  • VQ-VAE: uses a discrete codebook for the latent space, and became a key component in image and audio generation, including early versions of DALL-E and music models.
  • Hierarchical VAEs: use several levels of latent variables for greater detail.
  • Latent diffusion’s autoencoder: a VAE-style compressor lets latent diffusion models work in a smaller space, as in Stable Diffusion.

Applications of VAEs

VAEs generate images, music and text, create synthetic data for training and privacy-sensitive uses, detect anomalies by flagging inputs that the model reconstructs poorly, denoise and impute missing data, and compress data. In drug discovery, they explore a continuous space of molecules and optimize them for desired properties. In genomics, they model single-cell data. In robotics and reinforcement learning, they learn compact representations of sensory input. In creative tools, they power interpolation and style mixing.

VAEs vs. GANs and diffusion models

VAEs train stably and give a useful latent space with explicit probability, but their images are often blurrier than those from GANs, because the reconstruction loss averages over possibilities. GANs give sharper images but are harder to train. Diffusion models give the highest quality and diversity but generate slowly. Many modern systems combine them, using a VAE to compress images and a diffusion model to generate in the compressed space.

Advantages and limitations

The advantages are stable training, a continuous and meaningful latent space, the ability to both generate and infer, and a principled probabilistic basis. The limitations include blurry output with simple losses, a tendency of the model to ignore the latent variables when the decoder is very powerful, a problem called posterior collapse, and the restriction to simple distributions such as Gaussians for the latent variables.

A worked example

A bank wants to detect unusual card transactions. It trains a VAE on millions of normal transactions, with features such as amount, merchant type and time. The model learns to reconstruct typical patterns well. When a new transaction arrives, the system encodes and decodes it and measures the reconstruction error. A fraudulent transaction that differs from the normal pattern, such as a large purchase abroad minutes after a local one, reconstructs poorly and gets a high anomaly score. Analysts review the highest scores, and the team tunes the threshold to keep false alarms manageable.

Tips for training a VAE

Start with a modest latent size and a simple architecture, and watch both loss terms. If the regularization term drops to zero while reconstructions stay poor, the model may be ignoring its latent variables, and a gradual increase of the regularization weight, called KL annealing, often helps. Normalize inputs, use convolutional layers for images and check results by decoding random samples and by interpolating between real examples. Evaluate generated data against held-out real data, not only by eye.

FAQs

What does variational mean in VAE? It refers to variational inference, a method that approximates a hard probability distribution with a simpler one that is optimized to be close.

Can a VAE generate new images? Yes. Sample a random latent vector and pass it through the decoder.

Why are VAE images blurry? The reconstruction loss encourages averaging over uncertain details, which smooths them.

Key facts

  • Diederik Kingma and Max Welling introduced the variational autoencoder in 2013.1
  • A VAE encoder outputs the mean and variance of a distribution over latent variables, and the decoder reconstructs data from a sample of it.1
  • The training objective, the evidence lower bound, combines a reconstruction term with a term that keeps the latent distribution close to a prior.2

Related concepts

Quick checkHow does a VAE differ from a standard autoencoder?Show answer

A standard autoencoder maps each input to a single point, while a VAE maps it to a probability distribution and is trained to keep the latent space smooth, so sampling from it generates new, plausible data.

Sources

  1. Kingma and Welling, Auto-Encoding Variational Bayes, https://arxiv.org/abs/1312.6114
  2. Doersch, Tutorial on Variational Autoencoders, https://arxiv.org/abs/1606.05908
  3. Kingma and Welling, An Introduction to Variational Autoencoders, https://arxiv.org/abs/1906.02691

Editorially reviewed by Specialty Digest Editorial TeamLast reviewed November 17, 2026Researched and drafted with AI assistanceReport an issue