DEV Community

zeromathai
zeromathai

Posted on Originally published at zeromathai.com

Variational Autoencoders Explained: From Latent Representations to Probabilistic Generation

An autoencoder can reconstruct a handwritten digit from a compressed representation. But what happens when you give its decoder a randomly selected latent vector instead of encoding an existing image?

There is no guarantee that the result will resemble a meaningful handwritten digit. Learning to reconstruct data and learning to generate data are different problems.

A Variational Autoencoder (VAE) addresses this distinction by combining representation learning, probabilistic modeling, and variational inference. Instead of encoding an input as a fixed latent vector, it represents the input as a probability distribution over possible latent codes.

Understanding how these components fit together explains why VAEs use probabilistic encoders and decoders, how their training objective is constructed, and how they generate new data.

From Autoencoders to Generative Models

A conventional encoder–decoder architecture transforms an input into an internal representation and uses that representation to produce an output.

x→Encoderh→Decodery x\xrightarrow{\mathrm{Encoder}}h\xrightarrow{\mathrm{Decoder}}y

An autoencoder specializes this architecture for input reconstruction:

h=fϕ(x) h=f_{\phi}(x)
x~=gθ(h)=gθ(fϕ(x))≈x \tilde{x}=g_{\theta}(h)=g_{\theta}(f_{\phi}(x))\approx x

Here, fϕf_{\phi} and gθg_{\theta} are the encoder and decoder, ϕ\phi and θ\theta are their trainable parameters, and hh is the latent representation.

A typical reconstruction objective is mean squared error (MSE):

Lrecon1D∑i=1D(xi−x~i)2 \mathcal{L}_{\mathrm{recon}} \frac{1}{D}\sum_{i=1}^{D}(x_i-\tilde{x}_i)^2

Here, DD is the dimensionality of the input. By minimizing reconstruction error, the model learns to preserve information needed to reconstruct its inputs.

Because the input itself serves as the reconstruction target, separate labels are unnecessary. The learned representations can also support tasks such as classification and clustering.

However, low reconstruction error does not necessarily indicate that the encoder has learned useful features. A sufficiently flexible model could simply learn to copy its input.

An undercomplete autoencoder uses a latent representation with fewer dimensions than the input, encouraging the encoder to retain important information. An overcomplete autoencoder uses a latent representation with more dimensions than the input, allowing richer representations but potentially requiring additional constraints to prevent simple copying.

Neither architecture inherently defines how to select latent vectors for generating new data. To move from reconstruction to generation, we need a distribution from which latent variables can be sampled and a model that describes how those variables produce observations.

Define a Generative Process Before Learning an Encoder

Consider handwritten images. Changing the thickness or slant of a digit affects multiple pixels simultaneously. A latent variable can represent an underlying factor that influences several observed components.

A probabilistic latent variable model defines generation in two steps:

z∼p(z) z\sim p(z)
x∼pθ(x∣z) x\sim p_{\theta}(x\mid z)

The resulting joint distribution is:

pθ(x,z)=p(z)pθ(x∣z) p_{\theta}(x,z)=p(z)p_{\theta}(x\mid z)

The prior p(z)p(z) determines how latent variables are selected. The conditional distribution pθ(x∣z)p_{\theta}(x\mid z) determines how observations are generated from them.

This structure allows dependencies between observed components to emerge through shared latent variables, even when those components are modeled as conditionally independent given zz .

Marginal likelihood

Different latent variables can produce similar observations. Evaluating how well the model explains an observed input therefore requires considering all possible latent variables:

pθ(x)∫pθ(x,z) dz∫p(z)pθ(x∣z) dz p_{\theta}(x) \int p_{\theta}(x,z)\,dz \int p(z)p_{\theta}(x\mid z)\,dz

This operation is called marginalization. The resulting marginal probability or density is the marginal likelihood of the observed data. For discrete latent variables, the integral becomes a sum.

VAEs belong to the likelihood-based family of generative models. Unlike implicit models such as GANs, they define probability distributions and optimize a likelihood-related objective.

Computing the marginal likelihood exactly can become intractable when the latent space is high-dimensional and the conditional distribution is parameterized by a complex neural network. Variational inference and the ELBO provide a way to train the model without evaluating this integral directly.

Variational Inference: Learning the Reverse Direction

Generation proceeds from latent variables to observations. Learning also requires the reverse direction: given an observation, which latent variables could explain it?

Bayes' theorem defines the posterior:

pθ(z∣x)p(z)pθ(x∣z)pθ(x) p_{\theta}(z\mid x) \frac{p(z)p_{\theta}(x\mid z)} {p_{\theta}(x)}

The numerator combines the prior with the conditional likelihood. The denominator is the marginal likelihood, which normalizes the posterior but is difficult to compute directly.

Monte Carlo estimation using samples from the prior is possible. However, it can be inefficient when the latent variables that explain an observation occupy only a narrow region of the latent space.

Variational inference addresses this problem by introducing a computationally manageable approximation to the true posterior.

Given a variational family Q\mathcal{Q} , the objective is:

q∗(z)arg⁡min⁡q∈QDKL(q(z) ∣ pθ(z∣x)) q^*(z) \underset{q\in\mathcal{Q}}{\arg\min} D_{\mathrm{KL}}\left( q(z)\,|\,p_{\theta}(z\mid x) \right)

KL divergence measures the discrepancy between the approximate and true posterior:

DKL(q(z) ∣ pθ(z∣x))Ez∼q(z)[log⁡q(z)pθ(z∣x)] D_{\mathrm{KL}}\left( q(z)\,|\,p_{\theta}(z\mid x) \right) \mathbb{E}{z\sim q(z)} \left[ \log\frac{q(z)}{p{\theta}(z\mid x)} \right]

KL divergence is non-negative and becomes zero when the distributions match. It is generally asymmetric, so it is not a distance metric in the usual mathematical sense.

A mean-field approximation simplifies inference by factorizing the approximate distribution:

q(z)=∏k=1Kqk(zk) q(z)=\prod_{k=1}^{K}q_k(z_k)

This independence assumption belongs to the approximation, not necessarily to the true posterior. It improves computational tractability but may prevent the approximation from capturing complex dependencies between latent variables.

Amortized inference

Using a Gaussian approximation allows inference to focus on distribution parameters such as means and variances. Optimizing a separate set of parameters for every observation, however, would require substantial computation.

A VAE instead trains a shared encoder to predict those parameters:

λx=fϕ(x) \lambda_x=f_{\phi}(x)
qϕ(z∣x)=q(z;fϕ(x)) q_{\phi}(z\mid x)=q(z;f_{\phi}(x))

Here, λx\lambda_x denotes the variational distribution parameters associated with input xx .

This approach is called amortized inference. Once trained, the encoder can construct an approximate posterior for a new observation through a forward pass rather than performing a separate iterative optimization.

The encoder is therefore more than a feature extractor: it is a learned inference function.

ELBO: Turning Intractable Inference into a Trainable Objective

Directly minimizing KL divergence from the true posterior still appears to require access to that posterior. Substituting Bayes' theorem into the divergence reveals a more useful formulation:

DKL(q(z) ∣ pθ(z∣x))Eq(z)[log⁡q(z)−log⁡pθ(x,z)]+log⁡pθ(x) D_{\mathrm{KL}}\left( q(z)\,|\,p_{\theta}(z\mid x) \right) \mathbb{E}{q(z)} [\log q(z)-\log p{\theta}(x,z)] + \log p_{\theta}(x)

For fixed xx and θ\theta , the log marginal likelihood does not depend on the approximate distribution. Its exact value is therefore unnecessary when optimizing that distribution.

This leads to the Evidence Lower Bound (ELBO):

L(q,θ;x)Eq(z)[log⁡pθ(x,z)−log⁡q(z)] \mathcal{L}(q,\theta;x) \mathbb{E}{q(z)} [\log p{\theta}(x,z)-\log q(z)]

The relationship between the ELBO and the log marginal likelihood is:

log⁡pθ(x)L(q,θ;x)+DKL(q(z) ∣ pθ(z∣x)) \log p_{\theta}(x) \mathcal{L}(q,\theta;x) + D_{\mathrm{KL}}\left( q(z)\,|\,p_{\theta}(z\mid x) \right)

Because KL divergence is non-negative:

L(q,θ;x)≤log⁡pθ(x) \mathcal{L}(q,\theta;x) \leq \log p_{\theta}(x)

For a fixed generative model, maximizing the ELBO is equivalent to minimizing the divergence between the approximate and true posterior. The bound becomes exact when the two distributions match.

The two terms that define VAE learning

Substituting the factorized joint distribution into the ELBO gives the familiar VAE objective:

ELBO(x,θ,ϕ)Ez∼qϕ(z∣x)[log⁡pθ(x∣z)]DKL(qϕ(z∣x) ∣ p(z)) \mathrm{ELBO}(x,\theta,\phi) \mathbb{E}{z\sim q{\phi}(z\mid x)} [\log p_{\theta}(x\mid z)] D_{\mathrm{KL}}\left( q_{\phi}(z\mid x)\,|\,p(z) \right)

The objective contains two complementary terms:

  • Reconstruction term: measures how well latent variables sampled from the approximate posterior explain the observed data.
  • Regularization term: measures how far the input-specific approximate posterior deviates from the shared prior used for generation.

The two KL divergences appearing in the derivation serve different purposes:

  • The divergence from the true posterior measures the gap between the ELBO and the log marginal likelihood.
  • The divergence from the prior acts as a regularization term inside the ELBO.

A small prior KL divergence does not, by itself, imply accurate posterior approximation.

During joint optimization of the encoder and decoder, the generative model also changes. Increasing the ELBO therefore does not guarantee an increase in the exact log marginal likelihood at every optimization step.

What a VAE Actually Computes

The architecture follows directly from the probabilistic model and its inference objective.

Input
↓
Encoder
↓
Approximate posterior parameters
↓
Latent sampling
↓
Latent vector
↓
Decoder
↓
Output distribution parameters
Enter fullscreen mode Exit fullscreen mode

Unlike a deterministic autoencoder, a VAE uses an encoder and decoder that parameterize conditional probability distributions, with a sampled latent vector connecting them.

Encoder: predict a distribution

A common VAE uses a Gaussian approximate posterior with diagonal covariance:

qϕ(z∣x)N(z;μϕ(x),Σϕ(x)) q_{\phi}(z\mid x) \mathcal{N}\left( z;\mu_{\phi}(x),\Sigma_{\phi}(x) \right)
Σϕ(x)diag⁡(σϕ,12(x),…,σϕ,K2(x)) \Sigma_{\phi}(x) \operatorname{diag}\left( \sigma_{\phi,1}^{2}(x), \ldots, \sigma_{\phi,K}^{2}(x) \right)

For a latent space with KK dimensions, the encoder determines KK means and KK variances.

The mean vector specifies the center of the distribution, while the variances determine the spread along each latent dimension. Using diagonal covariance constrains the conditional covariances between different latent dimensions to zero.

Even when the distribution parameters remain the same for a given input, sampling from that distribution can produce different latent vectors. The decoder receives a sampled vector, not the entire posterior distribution.

Prior: define where generation starts

Generating data without an existing input requires a shared distribution from which latent variables can be sampled.

A standard choice is the multivariate standard normal distribution:

p(z)N(z;0,I)∏k=1KN(zk;0,1) p(z) \mathcal{N}(z;0,I) \prod_{k=1}^{K}\mathcal{N}(z_k;0,1)

This prior is easy to sample from and allows a closed-form KL divergence calculation when the approximate posterior is Gaussian with diagonal covariance.

What makes a latent space useful for generation?

A latent space suitable for generation should exhibit two desirable properties:

  • Continuity: nearby latent vectors decode into similar observations, allowing gradual changes in latent codes to produce gradual changes in generated data.
  • Completeness: sampling from relevant regions of the latent space produces meaningful observations.

A conventional autoencoder can leave untrained regions between latent codes associated with actual observations. Probabilistic encoding and KL regularization help alleviate this problem.

However, a standard normal prior and KL regularization do not guarantee continuity or completeness. Independence between prior dimensions does not automatically imply that meaningful factors of variation will be disentangled.

Decoder Design Determines the Reconstruction Loss

A VAE decoder defines a conditional probability distribution rather than directly returning a reconstructed value:

pθ(x∣z)p(x;gθ(z)) p_{\theta}(x\mid z) p(x;g_{\theta}(z))

The reconstruction objective follows from the negative log-likelihood:

ℓNLL(x,z)−log⁡pθ(x∣z) \ell_{\mathrm{NLL}}(x,z) -\log p_{\theta}(x\mid z)

The interpretation of a decoder output depends on the chosen distribution. For example, a pixel output of 0.8 could represent a mean intensity under a Gaussian decoder or the probability of a pixel being 1 under a Bernoulli decoder.

Gaussian decoder

For continuous observations, the decoder can parameterize a Gaussian distribution:

pθ(x∣z)N(x;μθ(z),Σθ(z)) p_{\theta}(x\mid z) \mathcal{N}\left( x;\mu_{\theta}(z),\Sigma_{\theta}(z) \right)

With diagonal covariance:

Σθ(z)diag⁡(σ12(z),…,σD2(z)) \Sigma_{\theta}(z) \operatorname{diag}\left( \sigma_1^2(z),\ldots,\sigma_D^2(z) \right)

The decoder can predict both the mean and variance, or it can predict only the mean while keeping the variance fixed.

With fixed isotropic covariance and variance τ2\tau^2 , the negative log-likelihood becomes:

−log⁡pθ(x∣z)D2log⁡(2πτ2)+12τ2∣x−μθ(z)∣2 -\log p_{\theta}(x\mid z) \frac{D}{2}\log(2\pi\tau^2) + \frac{1}{2\tau^2} |x-\mu_{\theta}(z)|^2

Under this assumption, minimizing negative log-likelihood is equivalent to minimizing squared reconstruction error up to a fixed scaling factor and additive constant.

If the variance is learned, the objective also depends on the variance parameters and is no longer equivalent to ordinary MSE.

Bernoulli decoder

For binary observations, the decoder predicts the probability βi(z)\beta_i(z) that each output component equals 1.

A conditionally independent Bernoulli decoder defines:

pθ(x∣z)∏i=1Dβi(z)xi(1−βi(z))1−xi p_{\theta}(x\mid z) \prod_{i=1}^{D} \beta_i(z)^{x_i} (1-\beta_i(z))^{1-x_i}

Its negative log-likelihood is:

−log⁡pθ(x∣z)−∑i=1D[xilog⁡βi(z)+(1−xi)log⁡(1−βi(z))] -\log p_{\theta}(x\mid z) -\sum_{i=1}^{D} \left[ x_i\log\beta_i(z) + (1-x_i)\log(1-\beta_i(z)) \right]

This corresponds to the sum of binary cross-entropy terms.

Categorical decoder

For categorical observations, the decoder predicts a probability for each possible category, typically using softmax:

pθ(x∣z)Cat⁡(x;γ(z)) p_{\theta}(x\mid z) \operatorname{Cat}(x;\gamma(z))

The category probabilities satisfy:

γj(z)≥0,∑j=1Cγj(z)=1 \gamma_j(z)\geq 0, \qquad \sum_{j=1}^{C}\gamma_j(z)=1

For a one-hot observation, the negative log-likelihood is:

−log⁡pθ(x∣z)−∑j=1Cxjlog⁡γj(z) -\log p_{\theta}(x\mid z) -\sum_{j=1}^{C}x_j\log\gamma_j(z)

This is categorical cross-entropy.

Decoder distribution Observation type Distribution parameters Reconstruction loss
Gaussian Continuous Mean and variance Gaussian NLL; squared error under fixed isotropic covariance
Bernoulli Binary Success probabilities Binary cross-entropy
Categorical Categorical Category probabilities Categorical cross-entropy

The implementation principle is straightforward: choose the observation distribution first, then derive the reconstruction loss from its likelihood.

Distribution means versus generated samples

Returning a representative value from the output distribution is different from sampling an actual observation.

The distribution mean is:

x^Epθ(x∣z)[x] \hat{x} \mathbb{E}{p{\theta}(x\mid z)}[x]

An actual sample is obtained through:

xsample∼pθ(x∣z) x_{\mathrm{sample}} \sim p_{\theta}(x\mid z)

A Gaussian mean can serve as a representative continuous output. A Bernoulli mean, however, represents a success probability rather than an actual binary sample.

The VAE Loss: Reconstruction and Latent Regularization

Neural network optimization typically minimizes a loss, so the VAE minimizes the negative ELBO:

LVAE(x,θ,ϕ)−ELBO(x,θ,ϕ) \mathcal{L}_{\mathrm{VAE}}(x,\theta,\phi) -\mathrm{ELBO}(x,\theta,\phi)

Equivalently:

LVAE−Ez∼qϕ(z∣x)[log⁡pθ(x∣z)]⏟Lrecon+DKL(qϕ(z∣x) ∣ p(z))⏟LKL \mathcal{L}_{\mathrm{VAE}} \underbrace{ -\mathbb{E}{z\sim q{\phi}(z\mid x)} [\log p_{\theta}(x\mid z)] }{\mathcal{L}{\mathrm{recon}}} + \underbrace{ D_{\mathrm{KL}}\left( q_{\phi}(z\mid x)\,|\,p(z) \right) }{\mathcal{L}{\mathrm{KL}}}

Optimizing reconstruction alone does not ensure that latent representations align with the prior. Conversely, optimizing only the KL term can cause input-specific approximate posteriors to match the prior and lose information that distinguishes different observations.

Computing the Gaussian KL divergence

For a diagonal Gaussian approximate posterior and a standard normal prior, the KL term has a closed-form expression:

LKL12∑k=1K[μk2+σk2−1−log⁡σk2] \mathcal{L}_{\mathrm{KL}} \frac{1}{2} \sum_{k=1}^{K} \left[ \mu_k^2+\sigma_k^2-1-\log\sigma_k^2 \right]

In practice, the encoder commonly predicts log variance rather than variance directly:

vk=log⁡σk2 v_k=\log\sigma_k^2

The variance and standard deviation are recovered through:

σk2=exp⁡(vk),σk=exp⁡(vk2) \sigma_k^2=\exp(v_k), \qquad \sigma_k=\exp\left(\frac{v_k}{2}\right)

Exponentiating the log variance ensures a positive variance. The KL loss can then be computed directly from the encoder outputs:

LKL12∑k=1K[μk2+exp⁡(vk)−1−vk] \mathcal{L}_{\mathrm{KL}} \frac{1}{2} \sum_{k=1}^{K} \left[ \mu_k^2+\exp(v_k)-1-v_k \right]

Estimating the reconstruction expectation

The reconstruction term is an expectation over the approximate posterior. With a neural network decoder, this expectation is generally difficult to evaluate analytically.

Monte Carlo estimation approximates it with a sample average:

Lrecon≈−1L∑l=1Llog⁡pθ(x∣z(l)) \mathcal{L}{\mathrm{recon}} \approx -\frac{1}{L} \sum{l=1}^{L} \log p_{\theta}(x\mid z^{(l)})
z(l)∼qϕ(z∣x) z^{(l)}\sim q_{\phi}(z\mid x)

Here, LL is the number of latent samples used to estimate the expectation.

Increasing the number of samples generally reduces estimation variability but increases computational cost. Mini-batch training and repeated parameter updates make it practical to use relatively few samples per observation.

Both loss terms are now computable, but one problem remains: propagating gradients through the latent sampling step.

The Reparameterization Trick: Enabling Backpropagation Through Latent Sampling

The reconstruction loss must update not only the decoder but also the encoder that produced the latent distribution.

Direct sampling from the encoder's distribution does not explicitly provide the differentiable path required by ordinary backpropagation.

The reparameterization trick separates randomness from the trainable distribution parameters:

ϵ∼N(0,I) \epsilon\sim\mathcal{N}(0,I)
zμϕ(x)+σϕ(x)⊙ϵ z \mu_{\phi}(x) + \sigma_{\phi}(x)\odot\epsilon

Using log variance, the same operation becomes:

zμϕ(x)+exp⁡(vϕ(x)2)⊙ϵ z \mu_{\phi}(x) + \exp\left(\frac{v_{\phi}(x)}{2}\right) \odot\epsilon

Here, ϵ\epsilon is a random noise vector sampled independently of the encoder parameters, and ⊙\odot denotes element-wise multiplication.

The resulting latent vector follows the same Gaussian distribution as a direct sample. Once the random noise is sampled, however, the transformation is differentiable with respect to the distribution parameters:

∂zk∂μk=1,∂zk∂σk=ϵk \frac{\partial z_k}{\partial\mu_k}=1, \qquad \frac{\partial z_k}{\partial\sigma_k}=\epsilon_k

Reparameterization preserves randomness while providing a differentiable path from the sampled latent vector to the encoder parameters.

Monte Carlo estimation and reparameterization therefore solve complementary problems:

  • Monte Carlo estimation approximates the expected reconstruction loss.
  • Reparameterization allows gradients from that estimate to reach the encoder.

Putting the Training Pipeline Together

Combining the closed-form Gaussian KL term with the sampled reconstruction term gives the practical VAE objective:

LVAE(x,θ,ϕ)≈12∑k=1K[μk2+σk2−1−log⁡σk2]1L∑l=1Llog⁡pθ(x∣z(l)) \mathcal{L}{\mathrm{VAE}}(x,\theta,\phi) \approx \frac{1}{2} \sum{k=1}^{K} \left[ \mu_k^2+\sigma_k^2-1-\log\sigma_k^2 \right] \frac{1}{L} \sum_{l=1}^{L} \log p_{\theta}(x\mid z^{(l)})

Each latent sample is obtained through reparameterization:

z(l)μϕ(x)+σϕ(x)⊙ϵ(l),ϵ(l)∼N(0,I) z^{(l)} \mu_{\phi}(x) + \sigma_{\phi}(x)\odot\epsilon^{(l)}, \qquad \epsilon^{(l)}\sim\mathcal{N}(0,I)

The training procedure consists of five operations:

  1. Encoding: compute the mean and log variance from the input.
  2. Sampling: draw standard normal noise and construct a latent vector through reparameterization.
  3. Decoding: use the latent vector to parameterize the output distribution.
  4. Loss calculation: compute the negative log-likelihood and KL divergence.
  5. Backpropagation: compute gradients from the combined loss and update the encoder and decoder parameters.

The important implementation detail is that the reconstruction loss has a gradient path through the decoder, sampled latent vector, and encoder.

For a standard VAE with a fixed prior, the encoder receives gradients from both loss terms:

∇ϕLVAE∇ϕLKL+∇ϕLrecon \nabla_{\phi}\mathcal{L}_{\mathrm{VAE}} \nabla_{\phi}\mathcal{L}{\mathrm{KL}} + \nabla{\phi}\mathcal{L}_{\mathrm{recon}}

The decoder receives gradients from the reconstruction term:

∇θLVAE∇θLrecon \nabla_{\theta}\mathcal{L}_{\mathrm{VAE}} \nabla_{\theta}\mathcal{L}_{\mathrm{recon}}

Both networks are jointly optimized over the training dataset:

(θ,ϕ)arg⁡min⁡θ,ϕ∑i=1NLVAE(x(i),θ,ϕ) (\theta^,\phi^) \underset{\theta,\phi}{\arg\min} \sum_{i=1}^{N} \mathcal{L}_{\mathrm{VAE}} (x^{(i)},\theta,\phi)

Training, Reconstruction, and Generation Are Different Operations

A VAE uses the same decoder for all three operations. What changes is the origin of the latent vector and the purpose of the computation.

Operation Latent source Encoder required? Purpose
Training Approximate posterior Yes Optimize encoder and decoder
Reconstruction Approximate posterior Yes Reconstruct an existing observation
Generation Prior distribution No Produce a new observation

During training and reconstruction, latent variables are conditioned on an existing input:

z∼qϕ(z∣x) z\sim q_{\phi}(z\mid x)

During generation, latent variables come directly from the prior:

z∼p(z) z\sim p(z)

The decoder then defines the distribution from which a new observation can be sampled:

xsample∼pθ(x∣z) x_{\mathrm{sample}}\sim p_{\theta}(x\mid z)

The generation pipeline does not require an encoder or an existing observation:

Prior distribution
↓
Sample z
↓
Decoder
↓
Output distribution
↓
Sample data
Enter fullscreen mode Exit fullscreen mode

This explains why the prior matters during training. The decoder must learn to interpret latent representations in a space that will also be used when no original observation is available.

Limitations of the Standard VAE

The standard VAE makes several modeling choices that improve computational tractability but also introduce limitations.

A diagonal Gaussian approximate posterior may fail to capture complex dependencies in the true posterior. Likewise, a standard normal prior provides a convenient sampling distribution but does not guarantee that every relevant region of the latent space produces meaningful observations.

The choice of observation distribution also constrains how reconstruction quality is evaluated. Gaussian and Bernoulli decoders, for example, make different probabilistic assumptions about the observed data.

Takeaway

A VAE is a probabilistic latent variable model with a learned inference network. The encoder approximates the posterior, the decoder defines the observation distribution, and the ELBO provides a tractable objective for learning both. Monte Carlo estimation approximates the expected reconstruction loss, while reparameterization allows gradients from that estimate to reach the encoder. Together, these components connect representation learning, probabilistic inference, and data generation within a single trainable architecture.

Originally published at zeromathai.com.

Original article: https://zeromathai.com/en/variational-autoencoder-vae-course-en/

Top comments (0)