DeepLLM Quiz
Machine Learning

KL divergence, conditional entropy and mutual information

10 questions on relative entropy, why it is not a distance, its link to maximum likelihood, conditional entropy and mutual information.

  • 10 questions
  • Stopwatch
  • Instant feedback

Shown publicly with your score. Don’t use your full real name.

Sample questions

Play now ↑

Answers stay hidden. Start the quiz to play them.

  1. Sample 1

    Which of these values can a KL divergence take?

    • Any real number, including negative ones
    • Zero or any positive number, but never a negative one
    • Only values between zero and one
  2. Sample 2

    You want to minimise the KL divergence from the unknown true distribution to your model, but you only have a finite set of training examples. What makes this possible?

    • The expectation under the true distribution can be approximated by an average over the training examples
    • The true distribution can always be found exactly from the model
    • The divergence doesn't depend on the true distribution

How it works

  • One question per screen. An answer is final once sent.
  • You see right away whether you were right, with a short explanation.
  • The stopwatch runs: on equal scores, the faster player ranks first.
  • Only your best attempt counts, so replaying is never risky.

About this quiz

When a model describes data with the wrong probabilities, there is a price to pay. If you use a code designed for one distribution to send data that actually follows another, your messages come out longer than they need to be, and the extra length, averaged over the data, is a precise number. That number is the Kullback-Leibler divergence, usually shortened to KL divergence. It is one of the most heavily used quantities in machine learning, because it measures how far a model's distribution is from the true one, and it sits behind loss functions, generative models and training methods you will meet again and again.

This quiz builds the idea from the coding picture. You will see what the extra cost means, why it can never be negative, and why it vanishes only when the two distributions are exactly the same. You will also see why it is not a true distance, because the cost of using one distribution to describe another is not the same as the other way round. A key result links it to the training of models: shrinking the divergence between the data and a model turns out to be the same as maximising the likelihood of the data.

The second half introduces two companions. Conditional entropy measures how much information is still missing about one variable once you know another. Mutual information turns the same idea around and asks how much knowing one variable reduces your uncertainty about the other. It is defined as the divergence between the actual joint distribution and what it would be if the variables were independent, which makes it zero exactly when they are, and positive whenever they share information.

Frequent misunderstandings are worth clearing up. Treating KL divergence as a distance leads people to expect a symmetry it does not have. Treating a divergence of zero as merely « small » misses the fact that it identifies equal distributions exactly. And confusing mutual information with correlation misses that mutual information captures any kind of dependence, not only straight-line trends. Keep one picture in mind while you answer: a model is a claim about how the data are distributed, and these quantities are different ways of asking how costly that claim is when it turns out to be a little off, and how much two variables really have to do with each other.

The quiz follows the quiz on entropy but can be taken on its own. It suits students and practitioners who want to understand loss functions properly. No calculus is required. There are 10 questions, each explained straight after you answer, and the whole quiz takes about four minutes.

Questions and answers

›How long does the quiz take?

About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. An explanation appears after every answer.

›Do I have to take the entropy quiz first?

No, but it helps. The idea of entropy as average surprise is used here without being explained again. If you are unsure what entropy means, try the quiz on entropy and surprise first, then come back.

›What is the KL divergence in plain words?

It measures how much extra information, on average, you need when you describe data from one distribution using a model of another. If your model were perfect, the extra cost would be zero. The worse the model, the larger the divergence. It is also called relative entropy.

›Why is the KL divergence not a distance?

A distance would give the same answer in both directions. KL divergence does not: the cost of using a model to describe the truth differs from the cost of using the truth to describe the model. It also doesn't satisfy the triangle inequality, so it is better described as a measure of dissimilarity.

›How is KL divergence connected to maximum likelihood?

If you try to make a model resemble the data-generating distribution by minimising the divergence, the only part that depends on the model's parameters is the negative log likelihood of the data. Minimising the divergence and maximising the likelihood therefore pick exactly the same parameters.

›What is conditional entropy?

It is the average extra information needed to specify one variable once another is already known. If knowing the first variable tells you almost everything about the second, the conditional entropy is small. If it tells you nothing, the conditional entropy equals the ordinary entropy of the second variable.

›What is mutual information?

It measures how much knowing one variable reduces your uncertainty about another. It is zero for independent variables and positive whenever they share information. Unlike correlation, it can detect curved and other non-linear relationships, because it is based on the whole distribution.

›Where do these quantities appear in practice?

KL divergence appears in training objectives for classifiers and generative models, in comparisons between a model and a reference, and in approximate inference. Mutual information is used for selecting informative features, and for understanding what a representation keeps or discards. In practice, the divergence is rarely computed in the abstract. It appears as the training loss for classifiers, where the model's predicted probabilities are compared with the true labels, and in generative models, where it keeps a learned distribution close to a simple reference. Mutual information is harder to estimate from data, which is one reason that simpler measures such as correlation are still so popular, even though they capture only part of the relationship between two variables.

More quizzes