Information Theory interview question

StatisticsInformation TheoryRecommender Systemshard

A streaming service checks how well a user's recommendation list matches their taste. The user's viewing history p splits drama / comedy / documentary as 0.5 / 0.3 / 0.2, and the recommended list q splits them as 0.8 / 0.2 / 0.0. Using natural logs, what are KL(p‖q) and KL(q‖p), and what follows?

  1. ABoth directions equal about 0.29 nats, because KL divergence is a symmetric distance and the documentary term drops out under the convention 0·log 0 = 0.
  2. BKL(p‖q) is infinite, because the list gives documentaries zero share where the user has 0.2, while KL(q‖p) ≈ 0.29 nats; Jensen–Shannon is a bounded, symmetric option.
  3. CKL(q‖p) is infinite, because the list's documentary share is zero, while KL(p‖q) ≈ 0.29 nats stays finite, so reversing the arguments of KL is enough to fix the metric.
  4. DBoth directions are infinite, because a zero share on either side makes KL diverge; Jensen–Shannon fixes this, being symmetric and bounded above by ln 2.
Show the answer and explanation

Correct answer: B, KL(p‖q) is infinite, because the list gives documentaries zero share where the user has 0.2, while KL(q‖p) ≈ 0.29 nats; Jensen–Shannon is a bounded, symmetric option.

Explanation Information Theory

KL(p‖q) = Σ p(x)·ln[p(x)/q(x)] is the expected extra log-loss from using q where the data follow p. It is ≥ 0, equals 0 only when p = q, and is not symmetric.

  • KL(p‖q): the documentary term is 0.2 · ln(0.2/0) = +∞. Whenever q puts zero mass where p has mass, KL(p‖q) is infinite: the list completely ignores a genre the user watches.
  • KL(q‖p) = 0.8·ln(0.8/0.5) + 0.2·ln(0.2/0.3) + 0·ln(0/0.2) = 0.3760 − 0.0811 + 0 = 0.2949 ≈ 0.29 nats. The convention 0·log 0 = 0 applies when the first argument is zero, so this direction stays finite.

Why the distractors fail: KL is not a distance (no symmetry, no triangle inequality), so the two directions differ. The zero-share problem is direction-specific, so KL is not infinite both ways. Reversing the arguments does give a finite number, but it asks a different question: in KL(q‖p) the missing genre contributes exactly 0, so the metric no longer punishes a list that ignores documentaries.

Jensen–Shannon compares both distributions with their mixture m = (p + q)/2: JS(p, q) = ½·KL(p‖m) + ½·KL(q‖m). Because m > 0 wherever either distribution has mass, JS is always finite, symmetric and at most ln 2 ≈ 0.693 nats (1 bit). Here m = (0.65, 0.25, 0.10) and JS ≈ 0.092 nats. Calibrated-recommendation methods take another route: they keep KL(p‖q̃) but smooth the list as q̃ = (1 − α)·q + α·p with a small α such as 0.01.

Interview tip: always state the direction and the log base when you report KL. For monitoring or similarity scores, prefer a bounded, symmetric measure such as Jensen–Shannon (its square root is a true metric), and handle zero counts explicitly with smoothing instead of silently dropping terms.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Statistics questions

  1. Two trained fraud models are scored on the same 5,000-transaction test set: AUC 0.912 for the gradient-boosted model and 0.904 for the logistic model. You…
  2. A bank's prior for the mean monthly card spend μ of a new customer segment, based on similar segments, is μ ~ N(400, 20²) €. A pilot with 64 customers gives a…
  3. Which measure of central tendency is more robust to outliers, the mean or the median, and why?
  4. Which statement about the normal distribution is correct?
  5. What does the central limit theorem (CLT) state?