Welcome to the final lesson of our first module. In our previous discussion, we established the powerful principle of Maximum Likelihood Estimation (MLE) and saw how it provides a probabilistic justification for common loss functions like Mean Squared Error. We ended with a preview that MLE is deeply connected to an information-theoretic concept called Kullback-Leibler divergence.
Today, we will delve into that connection. This lesson aims to formally derive Kullback-Leibler (KL) divergence, explore its fundamental properties, and most importantly, explain its direct relationship to the cross-entropy loss function that is ubiquitous in classification tasks. For your goal of understanding research literature, this is a crucial step. KL divergence is the language used to describe the "distance" between probability distributions, a core operation in the training of generative models for tasks like speech synthesis.
1. Constructing KL Divergence: From Intuition to Formula
Before we dive into the formal mathematics, it's incredibly helpful to understand why the formula for KL divergence looks the way it does. Instead of just presenting the formula, we will build it step-by-step from a simple, practical problem. This approach treats mathematics not as a set of given rules, but as an engineering process designed to solve a problem.
The following video does an excellent job of this constructive process, motivating each component of the final KL divergence equation.
The KL Divergence : Data Science Basics
This video from the channel ritvikmath walks through the "construction" of the KL divergence formula. It begins with a relatable problem and incrementally adds mathematical components to address the shortcomings of simpler approaches.
Please watch the main construction part of the video, from the beginning up to the presentation of the final formula (the entire construction). As you watch, focus on the answers to these questions, which correspond to the key steps in the derivation: The Goal (Problem setup): What is the fundamental problem we are trying to solve with the kindergarten fruit example? Asymmetry (Asymmetry property): Why is it desirable for our metric to be asymmetric? Note the notation KL(P||Q), which reads "the divergence of P from Q", where Q is the reference. The Ratio (Simple average issue): Why is a simple average of the probability ratios p(x)/q(x) not a good metric? The Logarithm (Log transformation): What property of the logarithm function makes it suitable for solving the issue with simple ratios? The Weighting (Final weighting): What is the final component added to the formula, and what is its justification?
This constructive process leads us to the final form of the KL divergence for discrete distributions, which is the expected value of the log-probability ratios, weighted by the probability distribution :
Here, is the "true" or target distribution we want to model, and is our model's approximation of . The KL divergence measures the "inefficiency" or "surprise" in using to represent .
2. Formal Definition and Properties of KL Divergence
With the intuition established, we can now proceed with the formal definitions and properties that you would encounter in a textbook or research paper.
Cross Entropy, KL Divergence, and Maximum Likelihood ...
This article by Lei Mao provides concise mathematical definitions.
Please read the short section defining Kullback-Leibler Divergence. Notice the formulas for both the continuous and discrete cases.
A crucial property of KL divergence is that it is non-negative. That is, , with equality holding if and only if . This aligns with our intuition of it being a "distance-like" measure. The proof of this property is a classic result that relies on Jensen's inequality. Given your background, following this formal proof will be a valuable exercise.
[PDF] Entropy, Relative Entropy and Mutual Information
This is a chapter from the canonical textbook "Elements of Information Theory" by Cover and Thomas. It provides rigorous derivations of the core properties of these measures.
Please read the proof of Theorem 2.6.3 (Information inequality). You will find it in the subsection "Jensen’s Inequality and its Consequences." Follow the steps from the theorem statement to the end of the proof. This derivation formally establishes the non-negativity of KL divergence.
3. The Relationship Between KL Divergence and Cross-Entropy
Now we arrive at the central point of our lesson: connecting KL divergence to the cross-entropy loss function. Let's start with the image below, which poses this very question.

To understand the relationship, we must first define its components: Entropy and Cross-Entropy.
Using the properties of logarithms, we can rewrite the KL divergence formula:
This expanded form reveals two important quantities.
- Shannon Entropy : This measures the average level of "information", "surprise", or "uncertainty" inherent in a variable's possible outcomes.
- Cross-Entropy : This measures the average number of bits needed to identify an event drawn from distribution when the coding scheme is optimized for an estimated distribution .
Comparing these definitions with our expanded KL divergence formula, we find the elegant relationship:
This equation is fundamental. It states that the KL divergence is the difference between the cross-entropy of with and the entropy of itself. It is the "extra" bits of information we need to encode events from because we used a code optimized for instead of the true distribution .
To see this derivation laid out clearly, please refer back to the article from Lei Mao.
Cross Entropy, KL Divergence, and Maximum Likelihood ...
This article clearly defines the components and then derives their relationship.
First, read the definition of Shannon Entropy and Cross Entropy. Then, follow the short derivation in the next section, Cross Entropy and KL Divergence, which puts these pieces together.
4. Application: Why We Minimize Cross-Entropy
This relationship directly explains why cross-entropy is the loss function of choice for classification problems. In a supervised learning context:
- is the true data distribution. For a given data point, this is typically a "one-hot" vector where the correct class has a probability of 1 and all others have a probability of 0.
- is the probability distribution predicted by our model (e.g., the output of a softmax layer).
Our goal is to make our model's prediction as close as possible to the true distribution . The natural way to measure this "closeness" is to minimize the KL divergence, .
Let's look at our optimization objective:
where represents the parameters of our model.
The crucial insight is that , the entropy of the true data distribution, is a fixed value. It is an intrinsic property of the dataset and does not depend on our model's parameters . We cannot change the labels of our data. Therefore, the term is a constant in our optimization problem.
This means that minimizing is mathematically equivalent to minimizing just the cross-entropy term, .
We use cross-entropy as our loss function because it is computationally simpler than KL divergence (we don't need to calculate ) and it leads to the exact same result in terms of the optimal model parameters.
Cross Entropy, KL Divergence, and Maximum Likelihood ...
This final section of the article makes the connection between the mathematical identity and its practical application in machine learning optimization.
Please read the section Optimization Using Cross Entropy or KL Divergence to see this argument formalized.
Conclusion
In this lesson, we have demystified one of the most important concepts from information theory and connected it directly to the practice of training neural networks.
Key Takeaways:
- Kullback-Leibler (KL) Divergence is an asymmetric measure of how one probability distribution diverges from a second, expected probability distribution . It quantifies the information lost when using to approximate .
- The core mathematical relationship is , where is the cross-entropy and is the Shannon entropy.
- In machine learning classification, minimizing the cross-entropy loss is equivalent to minimizing the KL divergence between the predicted distribution and the true data distribution. This is because the entropy of the true data, , is constant with respect to the model's parameters.
- This provides a principled, information-theoretic justification for using cross-entropy, complementing the probabilistic justification from Maximum Likelihood Estimation we saw in the last lesson.
With this, we conclude our module on the probabilistic foundations of generative models. You now have the necessary mathematical language—from Bayes' theorem to MLE and KL divergence—to interpret the objective functions and training procedures you will encounter in speech synthesis research papers.
In our next module, we will switch gears and focus on the input to these models: the speech signal itself. Our first lesson will cover how to mathematically represent a time-varying audio waveform in the frequency domain using the Short-Time Fourier Transform (STFT).