AI Glossary / Generative AI and language / Advanced

Variational autoencoder

Definition

A variational autoencoder, or VAE, is a probabilistic generative model that learns a latent-variable representation of data together with an approximate inference mechanism. Its encoder estimates a distribution over latent variables for an input, and its decoder defines a distribution over outputs given those variables. Training balances explaining the observed data with keeping the inferred latent distributions compatible with a chosen prior.

What it means

An ordinary deterministic autoencoder maps an input to a code and tries to reconstruct it. A VAE introduces an explicit probabilistic model: the code is treated as a latent random variable, and the encoder approximates which latent values could account for an observed input.
This distinction supports generation. After training, the system can sample a latent value from the prior and use the decoder to produce an output distribution. Encoding an existing example and generating a new example are therefore related but different operations.
The learned latent coordinates need not correspond to named human concepts. A two-dimensional picture of a latent space can be useful without proving that either axis has a stable semantic meaning.

How it works

The generative model combines a prior p(z) with a decoder likelihood p(x given z). The encoder supplies an approximate posterior q(z given x). Training commonly maximizes an evidence lower bound, or ELBO, consisting of expected reconstruction log-likelihood minus a KL-divergence term comparing q with the prior.
In a common Gaussian implementation, the encoder outputs means and variances. Sampling is written as z = mean + standard deviation × epsilon, where epsilon is standard normal noise. This reparameterization supports gradient-based optimization through the sampled latent representation.
The reconstruction term must match the specified observation model. A squared-error expression and a binary cross-entropy expression are not interchangeable without considering their underlying assumptions and scaling. The KL term is also not simply a second reconstruction error.

Three practical examples

  • A learning exercise generates small handwritten-digit images by sampling latent values and decoding them. Students distinguish these generated samples from reconstructions of particular input images.
  • A research team compresses complex observations into latent representations for exploration. It checks whether neighboring points correspond to useful similarities rather than assuming every visually smooth map is meaningful.
  • A prototype uses reconstruction behavior as one signal for unusual inputs. Its evaluation tests actual anomalies separately, because a generative training objective does not automatically create a reliable anomaly detector.

Think of it this way

Imagine describing an object with a range of plausible hidden explanations rather than one fixed code. A decoder uses a selected explanation to produce a possible observation, while training encourages the explanations to fit into a shared reference distribution.
It does not mean that the model has discovered the true physical causes of every observation or that its uncertainty is automatically calibrated for a business decision.

Worked example

Consider an original one-dimensional Gaussian example. For a particular input, let the approximate posterior have mean 1 and standard deviation 0.5, and let the prior be standard normal.
With epsilon = −0.4, reparameterization gives z = 1 + 0.5 × (−0.4) = 0.8. A different noise draw would generally give a different latent sample even for the same input.
For these Gaussian distributions, KL(q || p) is one half of mean squared plus variance minus one minus the natural logarithm of variance. Here it equals 0.5 × (1 + 0.25 − 1 − ln(0.25)), approximately 0.8181 nats.
Suppose the expected negative reconstruction log-likelihood is 2.3 nats. The negative ELBO is then 2.3 + 0.8181 = 3.1181 nats, and the ELBO is −3.1181. Minimizing the negative ELBO is equivalent to maximizing the ELBO.
The assumed reconstruction expectation is supplied for illustration; it is not derived from the single sample z = 0.8. In practice, sampling can estimate that expectation. The resulting bound is not generally equal to the exact data log-likelihood, and none of these numbers is a classification accuracy.

Illustrative case study

Fictional Hazel Learning builds a VAE demonstration for simple symbol images. The first presentation shows appealing reconstructions, but samples drawn from the prior are less convincing.
The team begins evaluating reconstruction and prior-based generation separately. It also checks how the implementation sums or averages reconstruction terms across pixels, because changing that scale alters their balance with the KL term.
A second issue appears when presenters describe one latent axis as “complexity” based on a few selected images. They test that description across a wider collection and find exceptions. The revised demonstration shows the observed pattern without presenting it as a guaranteed semantic control. Its value is explaining the model's behavior honestly, including where a convenient visual interpretation breaks down.

Common misconceptions and mistakes

A VAE is not merely an autoencoder with arbitrary noise added. The probabilistic model, approximate inference and variational objective define the approach.
The encoder's distribution is an approximation to the posterior, not automatic access to the exact posterior.
A small KL term alone does not prove a useful representation. It may accompany weak use of the latent variables, depending on the complete model and training behavior.
Sampling from the prior differs from sampling from an encoded input's posterior. Confusing those operations can make a reconstruction demonstration look like evidence of broader generation quality.

Business use

Specify whether the intended benefit is generation, representation learning, reconstruction or another task. Evaluate that outcome directly rather than relying only on the training loss.
Record the observation model, latent dimension and loss aggregation choices when comparing experiments. Loss values with different definitions or scaling may not be directly comparable.
If generated examples will support another workflow, test their usefulness there. Visual plausibility alone does not establish coverage of important cases, preservation of rare details or downstream performance.

People also ask

Does every VAE use a Gaussian posterior?

No. It is a common construction, but the broader framework permits other choices with suitable inference and optimization methods.

Does generation require an input example?

Prior-based generation does not; reconstruction does.

Is the ELBO the exact log-likelihood?

Generally no. It is a lower bound, with equality only under the relevant exact-posterior condition.

Check your understanding

What latent sample results from the illustrated noise draw?

Answer: 0.8.

What does the 0.8181 term compare?

Answer: The approximate posterior with the standard-normal prior.

Why assess prior samples separately?

Answer: Good reconstruction of supplied inputs does not alone demonstrate good generation from the prior.

Related terms

  • Latent variable
  • Prior (regularizer)
  • Reparameterization trick
  • Autoencoder
  • Generative model
  • approximate posterior
  • prior
  • ELBO
  • KL divergence

Learn next

Recalculate the example after changing the posterior mean or variance. Then trace the difference between encoding an observation and drawing a fresh latent value from the prior before decoding.

More in Generative AI and language

  • Undersampling - Undersampling reduces the number of training examples from selected groups, commonly an overrepresented class, to change the balance of a dataset.
  • Unidirectional language model - A unidirectional language model predicts tokens using context from one direction in a sequence.
  • Unsupervised Pretrained Network - An unsupervised pretrained network is a neural network whose parameters are first learned using an objective that does not require the eventual task's...
  • Vector quantization - Vector quantization represents an input vector by one of a finite set of representative vectors called a codebook.
  • Vibe coding - Vibe coding is an informal term for creating software by describing desired behavior to a generative AI system and iterating on what it produces.
  • Word tokenization - Word tokenization divides text into word-level units and, depending on the rules, separate punctuation or other tokens.

Sources

Kingma and Welling, Auto-Encoding Variational Bayes, original probabilistic formulation and variational objective. https://arxiv.org/pdf/1312.6114 Keras, Variational AutoEncoder example: Gaussian sampling and reconstruction-plus-KL training implementation. https://keras.io/examples/generative/vae/ The one-dimensional calculation and fictional demonstration are original teaching illustrations.

Previous: Variational approximation Next: Variational Bayes expectation maximization

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer