DEV Community

zeromathai
zeromathai

Posted on Originally published at zeromathai.com

Deep Generative Models: Four Ways to Make Complex Distributions Learnable

When developers first encounter deep generative models, it is easy to reduce them to one idea: models that generate new data.

That is only the visible outcome. The deeper problem is deciding how to represent a complex data distribution in a form that a model can compute and learn.

High-dimensional data such as images and audio can follow extremely complex distributions. A single simple probability model is not enough to represent them directly, so different generative model families restructure the problem in different ways.

An Autoregressive Model factorizes a joint distribution into conditional distributions. A Variational Autoencoder (VAE) introduces latent variables. A Flow-based Model starts from a simple distribution and transforms it through invertible mappings. A Generative Adversarial Network (GAN) takes a different route and learns a generation process without directly evaluating an explicit probability density.

A useful mental model is:

Deep generative modeling is not just about producing samples. It is about turning a difficult distribution-modeling problem into something the model can compute and learn.

Two Broad Families

One useful distinction is between Likelihood-based and Likelihood-Free approaches.

Likelihood-based models include:

  • Autoregressive Models
  • Variational Autoencoders
  • Flow-based Models
  • Diffusion Models
  • Score-based Models

GAN is a representative Likelihood-Free model.

This distinction matters because it reveals the structural choice behind each model family. A complex distribution can be decomposed into conditional distributions, represented indirectly through latent variables, transformed from a simpler distribution, or learned without directly computing its probability density.

Diffusion Models and Score-based Models also belong to the Likelihood-based side of this classification. Their detailed mechanisms, including Forward Diffusion, Reverse Diffusion, and Score Matching, are outside the scope here.

From KL Divergence to NLL

For Likelihood-based modeling, a natural goal is to make the model distribution close to the data distribution.

Let the true data distribution be pdatap_{\mathrm{data}} and the model distribution parameterized by θ\theta be pmodelp_{\mathrm{model}} .

We can express that goal by minimizing KL Divergence:

minθDKL[pdata(x)pmodel(x;θ)] \min_{\theta} D_{\mathrm{KL}}\left[p_{\mathrm{data}}(x)\,|\,p_{\mathrm{model}}(x;\theta)\right]

Expanding the KL Divergence gives:

DKL[pdatapmodel]Expdata[logpdata(x)]Expdata[logpmodel(x;θ)] D_{\mathrm{KL}}\left[p_{\mathrm{data}}\,|\,p_{\mathrm{model}}\right] \mathbb{E}{x\sim p{\mathrm{data}}}\left[\log p_{\mathrm{data}}(x)\right] \mathbb{E}{x\sim p{\mathrm{data}}}\left[\log p_{\mathrm{model}}(x;\theta)\right]

The first term depends only on the data distribution. If pdatap_{\mathrm{data}} is fixed, changing θ\theta does not affect it.

The model-dependent part is therefore:

minθExpdata[logpmodel(x;θ)] \min_{\theta} \mathbb{E}{x\sim p{\mathrm{data}}} \left[-\log p_{\mathrm{model}}(x;\theta)\right]

This is the Cross-Entropy term between the data distribution and the model distribution.

In practice, we do not know the full underlying data distribution, so the expectation is approximated using training samples. The resulting objective is Negative Log-Likelihood (NLL) minimization.

The optimization flow is:

Minimize KL Divergence
        ↓
Remove the entropy term independent of θ
        ↓
Minimize Cross-Entropy
        ↓
Minimize NLL on training data
Enter fullscreen mode Exit fullscreen mode

The intuition is simple: assign high probability to regions where real data occurs.

This connection is the basic picture when the model provides a way to work explicitly with Likelihood. When p(x)p(x) becomes difficult to optimize directly, the model needs a different structure.

That is where the major generative model families begin to diverge.

Strategy 1: Factorize the Distribution

An Autoregressive Model starts with a straightforward idea: if the full joint distribution is difficult to model at once, break it into a sequence of conditional distributions.

The Probability Chain Rule gives an exact factorization:

p(x)=i=1np(xix1,,xi1) p(x)=\prod_{i=1}^{n}p(x_i\mid x_1,\ldots,x_{i-1})

This is not an approximation introduced for convenience. It is an exact decomposition of the joint distribution.

The calculation proceeds through conditional terms such as p(x1)p(x_1) , then p(x2x1)p(x_2\mid x_1) , then p(x3x1,x2)p(x_3\mid x_1,x_2) , continuing until p(xnx1,,xn1)p(x_n\mid x_1,\ldots,x_{n-1}) .

That changes the modeling problem. Instead of asking how to represent one complicated p(x)p(x) directly, we ask how well the network can model each conditional distribution.

GPT, RNN, PixelRNN, PixelCNN, WaveNet, NADE, and MADE use different data and network structures, but they share this conditional factorization principle.

From an implementation perspective, the important thing to inspect is the ordering and conditioning structure. Each prediction must depend on the variables that precede it in the chosen factorization.

Strategy 2: Introduce a Latent Variable

A VAE restructures the problem differently.

Instead of factorizing the observed variables sequentially, it introduces an unobserved latent variable zz and models the observed data xx through that latent state.

The data distribution is written as:

p(x)=p(z)p(xz)dz p(x)=\int p(z)p(x\mid z)\,dz

Here, zz is the latent variable, p(z)p(z) defines its distribution, and p(xz)p(x\mid z) describes how an observation is generated from a particular latent state.

The structural flow is:

Latent state
     ↓
Conditional generation
     ↓
Observed data
Enter fullscreen mode Exit fullscreen mode

In probabilistic terms, the Decoder models p(xz)p(x\mid z) .

The VAE also needs a way to infer which latent states are plausible for a given observation. Its Encoder, also called the Recognition Network, does not simply map xx to one fixed latent value. It constructs an approximate distribution over zz given xx .

The Decoder, or Generative Network, models the conditional distribution of xx given zz .

The difficulty is that the exact Posterior over zz given an observation can be hard to compute. VAE addresses this with Variational Inference and trains by maximizing an ELBO.

The important point here is not the full ELBO derivation. It is the structural move: VAE combines latent-variable modeling with approximate inference so that a difficult p(x)p(x) becomes a learnable problem.

Strategy 3: Transform a Simple Distribution

Normalizing Flow takes another approach.

Where an Autoregressive Model decomposes a complex p(x)p(x) into conditional distributions, a Flow-based Model begins with a simple distribution and changes its shape through a sequence of transformations.

The structure is:

Simple Distribution
        ↓
Invertible Transformation
        ↓
Invertible Transformation
        ↓
        ...
        ↓
Target Distribution
Enter fullscreen mode Exit fullscreen mode

The key requirement is invertibility.

It is not enough to map values from a simple distribution into a more complicated one. The transformation must also allow the model to trace a transformed value back to where it came from.

That property keeps changes in probability density computable through the sequence of transformations.

This requirement also constrains the model architecture. A Flow-based Model cannot freely use arbitrary transformations if they violate invertibility.

The benefit is that the final data variable xx has an explicit probability density. Its Likelihood can therefore be computed, and training can directly optimize NLL on the observed data.

A useful implementation-level mental model is:

Preserve invertibility so that probability density remains computable while the distribution becomes progressively more complex.

Saying that a Flow-based Model models the data distribution does not mean the learned distribution becomes identical to the true data distribution. It means the architecture defines an explicit model distribution p(x)p(x) whose Likelihood can be computed and optimized.

Strategy 4: Learn Without Direct Density Evaluation

GAN changes the setup more substantially.

Instead of putting the explicit value of p(x)p(x) at the center of training, GAN introduces two competing models:

  • a Generator, which produces samples resembling real data,
  • a Discriminator, which tries to distinguish real samples from generated ones.

Their opposing objectives form a Minimax Problem.

The structural view is:

Generator
    ↓
Generated samples
    ↓
Discriminator
 ↙           ↘
Real      Generated
data        data
Enter fullscreen mode Exit fullscreen mode

As the Generator produces more convincing samples, the Discriminator has a harder time separating generated data from real data. As the Discriminator improves, the Generator is pushed to produce better samples.

The important difference from an Autoregressive Model or a Flow-based Model is that GAN training does not center on directly computing an explicit p(x)p(x) for each observation.

Instead, the interaction between the Generator and Discriminator provides the learning signal that pushes the Generator toward producing samples similar to those from the real data distribution.

That is why GAN is treated as a Likelihood-Free approach in this comparison.

The Structural Difference That Matters

The most useful way to compare these models is not by memorizing architecture names, but by asking how each one turns a complex distribution into a problem the model can compute and learn.

Model Structural move Core training view
Autoregressive Model Factorize p(x)p(x) into conditional distributions Model each conditional probability
VAE Introduce latent variable zz Approximate inference and optimize ELBO
Flow-based Model Apply invertible transformations Explicit density and NLL
GAN Avoid direct explicit density evaluation Generator–Discriminator Minimax learning

These approaches begin with the same fundamental difficulty: complex high-dimensional data distributions are hard to model directly.

What changes is the structure used to make learning possible.

Takeaway

When reading the implementation of a generative model, do not start with the layer names.

Start with the probability structure. Check whether the model factorizes the distribution, introduces latent variables and approximate inference, preserves density through invertible transformations, or learns through an adversarial objective without directly evaluating an explicit density.

Once that structural choice is clear, the architecture, objective, and training procedure become much easier to understand as parts of the same generative-modeling problem.

Originally published at zeromathai.com.

Original article: https://zeromathai.com/en/deep-generative-models-course-en/

Top comments (0)