The interview problem
Two models assign probabilities 0.1 and 0.9 to the correct class on one example. Compare the log loss of their probability ensemble with their average individual log loss. Then explain why averaging document perplexities does not generally produce corpus perplexity, and derive a lower bound on a latent-variable likelihood.
Original ML-fundamentals practice, not a reported company interview. Examples and calculations are original. Reference retrieved September 27, 2026; interview date not applicable.
1. Start with the direction and domain
For nonnegative weights wᵢ summing to one and a convex function f, f(Σwᵢxᵢ) ≤ Σwᵢf(xᵢ). Concave functions reverse the inequality. The expectation version is f(E[X]) ≤ E[f(X)] under suitable existence assumptions, including finite expectations for this discussion. The domain must contain the relevant values and their mean.
Natural log is concave on positive numbers, so E[log X] ≤ log E[X]. Negative log is convex, so −log E[X] ≤ E[−log X]. Exponential is convex on the real line. Do not memorize only the symbol: sketch a convex curve and its chord, or check x² on values −1 and 1, where f(mean) = 0 but mean f = 1.
Equality holds for a constant X. For strictly convex functions with the stated integrability assumptions, a nonconstant X gives strict inequality. A merely convex function can have equality across an affine region even when X varies. Negative weights are not covered by the weighted statement.
2. Work through the probability ensemble
On the given example, individual negative log losses are −ln(0.1) ≈ 2.302585 and −ln(0.9) ≈ 0.105361. Their average is 1.203973. The equally weighted probability ensemble assigns the true class probability 0.5 and has loss −ln(0.5) ≈ 0.693147. Its loss is lower than the average individual loss by approximately 0.510826.
This comparison is with the weighted average of constituent losses, not with the best constituent: the 0.9 model's loss is only 0.105361. Applying the pointwise inequality and then averaging over the same labeled examples preserves the guarantee for that evaluation set. It does not establish better accuracy, calibration or latency. The same pointwise log-loss inequality also holds on new data when the construction is unchanged, but the measured loss values and improvement over any particular constituent need not generalize.
The ensemble must average normalized class probabilities with the declared weights. Averaging logits and applying softmax is a different operation. An implementation that averages each model's reported loss evaluates a randomized choice of model in expectation, rather than the loss of the probability mixture. Those are different predictors and objectives.
3. Preserve aggregation order in evaluation
per-token true-class log probabilities
↓
negative log-likelihood sums + token counts
↓
aggregate sums and counts over the target corpus
↓
mean token loss → exponentiate onceSuppose document A has 100 evaluated tokens with mean negative log loss 1 nat, while document B has 900 tokens with mean loss 3 nats. Corpus mean loss is (100 × 1 + 900 × 3)/1,000 = 2.8, giving perplexity exp(2.8) ≈ 16.444647. The token-weighted average of document perplexities is 0.1 exp(1) + 0.9 exp(3) ≈ 18.348811. Convexity of exp explains why the latter is larger.
The unweighted mean document perplexity is approximately 11.401909, which answers yet another question. Jensen's direction applies when the weights and inputs match; changing from token weights to equal document weights breaks that comparison. Decide whether the unit of interest is a token, document or user before aggregating.
Record tokenization, masking and context boundaries. Summing losses from incompatible tokenizations does not make perplexity comparable. In distributed evaluation, return loss sums and valid-token counts from workers; an unweighted mean of worker means is not generally the corpus mean when token counts differ. Exclude masked tokens from both numerator and denominator.
4. Derive a likelihood bound with explicit support
For a fixed observed x and discrete latent z, let p(x) = Σz p(x,z). Choose a normalized q(z) that is positive wherever p(x,z) is positive. Then p(x) = E_q[p(x,z)/q(z)]. Assuming the necessary log expectations exist, concavity gives log p(x) ≥ E_q[log p(x,z) − log q(z)]. The right-hand side is an evidence lower bound, or ELBO.
Consider two latent states with joint values p(x,z₁)=0.2 and p(x,z₂)=0.3. Evidence is 0.5 and log evidence is −0.693147. With q=(0.5,0.5), the bound is 0.5 ln(0.4) + 0.5 ln(0.6) ≈ −0.713558. The gap is approximately 0.020411. The posterior is (0.4,0.6); choosing q equal to it makes p(x,z)/q(z) constant at 0.5 and closes the gap.
Under these assumptions the gap equals KL(q || p(z|x)). Raising a lower bound does not by itself prove that the exact likelihood rose when both the model and bound tightness change. If q omits positive joint support, the initial equality to the full evidence fails; do not write that equality without checking support. The ELBO can still be a valid lower bound in that case: the expectation of the ratio covers only the supported portion of the evidence, which is at most the full evidence. If q puts mass where the joint density is zero, the log term can be negative infinity.
5. Recognize estimation and numerical traps
If a positive estimator Ẑ has E[Ẑ]=Z and finite log expectation, Jensen gives E[log Ẑ] ≤ log Z. An unbiased estimate of a likelihood is therefore not generally an unbiased estimate of its log. This is an expectation statement: an individual sampled log estimate can exceed log Z. If zero estimates occur, the log may be undefined or negative infinity.
For positive probabilities near zero, clipping changes the evaluated objective. It can be an explicitly declared numerical convention, but it cannot preserve the exact mathematical guarantee for the original values automatically. Compute mixture log probabilities with log-sum-exp of log weights plus log probabilities to avoid avoidable underflow. Keep zero weights out of logarithms or handle them as negative infinity.
Do not apply a global curvature claim outside its domain. A nonlinear function need not be convex everywhere, and a ratio of averages is not interchangeable with an average of ratios merely because both are averages. Write the actual random variable, function and weights before invoking the theorem.
6. Follow-ups and self-review
Follow-ups: Does the ensemble beat every model? No, only their weighted average log loss under the stated construction. Can equal-document perplexity be a legitimate metric? Yes, if explicitly chosen, but it is not corpus token perplexity. When is the likelihood bound tight? When q equals the posterior; with full evidence support, this is equivalent to the importance ratio being constant q-almost surely. Does an unbiased estimator stay unbiased after logging? Generally not.
Score 0–2 each for inequality direction/domain, numerical ensemble comparison, consistent aggregation weights, support-aware bound derivation and limits of the conclusions. A strong answer names the quantity being averaged before doing algebra.
Sources and next steps
- Marco Taboga: Jensen's inequality — author-written textbook appendix, cited as 2021; validates the convex/concave statement, equality conditions and log direction.
The ML scenarios, calculations and evaluation pipeline are original applications. Continue with distillation objectives for another distinction between target probabilities and loss calculations.
Continue your preparation
Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.