Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 39

KL Divergence in Variational Inference: Mode-Seeking vs. Mode-Covering

Recommended resources

Hello! In our last lesson, we navigated the intricate derivation of the Evidence Lower Bound (ELBO), establishing it as the cornerstone objective for training Variational Autoencoders. We concluded that maximizing the ELBO is precisely equivalent to minimizing the KL divergence between our approximate posterior and the true, intractable posterior .

Today, we'll scrutinize a subtle but profound detail of that conclusion. KL divergence, as we've noted, is asymmetric: . The choice of which distribution comes first has dramatic consequences for the learning process. Our goal for this lesson is to contrast the behavior of "forward" and "reverse" KL divergence. By understanding their distinct "mode-covering" and "mode-seeking" properties, you will grasp not only a key concept in information theory but also the deep rationale behind the specific formulation used in variational inference.

1. Forward vs. Reverse KL: A Formal Distinction

Let's establish our notation. We have a true, complex data distribution that we want to approximate with a simpler model distribution . The two ways we can measure the divergence are:

  1. Forward KL Divergence:

    This is used in scenarios like standard maximum likelihood estimation. Minimizing this is equivalent to minimizing the cross-entropy , as is constant with respect to .

  2. Reverse KL Divergence:

    As we saw, variational inference minimizes a form of this: , where is our tractable approximation and is the intractable target .

The crucial difference lies in the expectation. Forward KL is an expectation over the true distribution , while Reverse KL is an expectation over the approximation . This seemingly small change leads to vastly different optimization landscapes and behaviors.


2. The Penalty Game: Mode-Covering vs. Mode-Seeking

The core intuition for why these two objectives behave differently comes from analyzing their behavior when probabilities are near zero. This is where the logarithm term can dominate.

Let's think about what each objective penalizes most harshly:

  • Forward KL (): Consider a point where the true probability is high, but our approximation is near zero. The term will become very large, and since it's weighted by , the overall divergence will explode. To avoid this infinite penalty, the approximation is forced to have non-zero mass wherever has mass. It must "cover" the entire support of . If is multimodal, will tend to spread itself out to cover all the modes, often resulting in a single, broad distribution that averages them. This is known as mode-covering or mean-seeking behavior.

  • Reverse KL (): Now consider a point where our approximation is high, but the true probability is near zero. The term will again become very large, and since it's weighted by , the divergence explodes. To avoid this, the approximation is forced to be zero (or very small) wherever is zero. It is penalized for placing probability mass in regions that are impossible under the true distribution. This is a "zero-forcing" property. Conversely, if is high but is zero, the contribution to the sum is zero. This means is not penalized for missing a mode of . It is free to pick one mode of and focus all its mass there, ensuring it doesn't place mass in the low-probability regions between modes. This is known as mode-seeking behavior.

The following article provides an excellent, detailed explanation of this phenomenon, complete with interactive visualizations.

Information Theory Fundamentals: Entropy, Cross-Entropy, and KL Divergence – Nima Sarang

This blog post by Nima Sarang perfectly dissects the difference between the two KL divergences. It builds the intuition from first principles.

First, read the brief section At Zero Probabilities to solidify the mathematical intuition. Then, read the main section Reverse KL vs Forward KL. As you read, pay close attention to the distinction he draws between what each form of KL penalizes and what it allows. The interactive plots in the article are particularly insightful for visualizing the resulting "mean-seeking" vs. "mode-seeking" optimization landscapes.

The video below also offers a concise and intuitive animated explanation of this core difference.

Fantastic KL Divergence and How to (Actually) Compute It

This video by Jia-Bin Huang provides a very clear visual analogy for the mode-covering vs. mode-seeking behavior.

Watch the segment from the asymmetry of KL. The animation of a single Gaussian trying to fit a bimodal distribution is a great mental model to hold onto.


3. A Clearer Picture

The image below provides a static but powerful visualization of this exact scenario. Here, the true distribution is a mixture of two Gaussians. We are trying to fit it with a single Gaussian, . The plots show the value of the KL divergence for different parameters (mean and standard deviation ) of our approximation . The darker regions represent lower KL divergence, which is our goal.

Contour plots of the optimization landscape for fitting a single Gaussian (q) to a bimodal Gaussian mixture (p). The x-axis is the mean of q, the y-axis is the standard deviation of q, and the color indicates the KL divergence value (darker is better). The red markers indicate the parameters of the underlying components of p and their mixture.

Let's analyze the two plots:

  • Reverse KL (Left Plot): This shows the landscape for minimizing , the objective used in variational inference. Notice that there are two distinct minima. The optimal strategy for is to place its mass squarely over one of the two modes of . It "seeks" a single mode and ignores the other. This is a classic mode-seeking landscape.

  • Forward KL (Right Plot): This shows the landscape for minimizing . Here, there is only one broad, shallow minimum located between the two modes of . The optimal becomes wide and averages the two modes, trying to "cover" the entire region where has mass. This is a classic mode-covering landscape.


4. Why Variational Inference Uses Reverse KL

Now we can answer the crucial question: why do VAEs and other variational methods minimize the reverse KL, ? There are two main reasons.

1. Practicality and Tractability:
This is the most compelling reason. The Reverse KL objective is . The expectation is taken with respect to our simple, approximate distribution . This means we can estimate the objective by drawing samples from —something we can easily do by design—and evaluating the term inside the expectation. This is the foundation of the reparameterization trick and Monte Carlo estimation of the ELBO.

If we were to use Forward KL, the objective would be . The expectation is with respect to the true posterior . But is precisely the intractable distribution we're trying to avoid! We cannot sample from it, so we cannot compute this objective. The choice of Reverse KL is, therefore, a deeply pragmatic one that makes the entire variational inference framework computationally feasible.

The video below, which you may recall from the previous lesson, frames the optimization problem in exactly this way, setting up the minimization of because it's the only tractable path forward.

Variational Inference | Evidence Lower Bound (ELBO) | Intuition & Visualization

This video provides the context for why we are minimizing this specific form of KL divergence.

Recall the setup from the problem formulation, where the goal is explicitly stated as minimizing D_{KL}(Q\|P). The derivation that follows from here relies entirely on this choice because it allows for the algebraic rearrangement that isolates the intractable terms, leading to the computable ELBO. Finally, the segment on equivalence reinforces that maximizing the ELBO we derived is equivalent to minimizing this reverse KL divergence.

2. Desirability of Mode-Seeking:
While the practical reason is paramount, the behavioral consequence is also often desirable. In many inference tasks, we want our model to produce a confident, unambiguous explanation. The mode-seeking nature of Reverse KL encourages the approximate posterior to find a single, high-density region in the latent space that corresponds to the input data. While this might lead to ignoring other, less likely interpretations (modes), it often results in sharper and more useful representations for tasks like generation.


Conclusion

In this lesson, we've unpacked the crucial asymmetry of KL divergence and understood its profound impact on optimization.

Key Takeaways:

  • Forward KL () is mode-covering. It penalizes the model for missing regions where the true distribution has mass, forcing to spread out and average over the modes of .
  • Reverse KL () is mode-seeking. It penalizes the model for assigning probability where has none, forcing to be selective and focus on a single mode of .
  • Variational Inference uses Reverse KL for two primary reasons:
    1. Tractability: The objective's expectation is with respect to the simple distribution , making it computable via sampling.
    2. Behavior: The resulting mode-seeking property often leads to sharp, confident latent representations.

This lesson concludes our module on Estimation and Inference. You now have a comprehensive understanding of the theory behind VAEs, from the individual information-theoretic building blocks to the full ELBO objective and the nuances of its optimization.

In our next module, we will pivot to a new area: Stochastic Processes. We'll start by revisiting the concept of Markov chains and exploring their properties, which form the essential mathematical groundwork for understanding the forward and reverse processes in Denoising Diffusion Probabilistic Models (DDPMs), the final paper you aim to implement.