What is the log-sum-exp trick, and why is it needed when maximizing a log-likelihood numerically?

Quick Overview

Asks what the log-sum-exp trick computes and why numerical maximum likelihood needs it. Tests your understanding of floating-point overflow and underflow, where sums of exponentials appear in softmax, mixture and latent-variable likelihoods, and how a single bad value breaks an optimizer.

What is the log-sum-exp trick, and why is it needed when maximizing a log-likelihood numerically?

Role: Data Scientist

Category: Statistics & Math

Difficulty: medium

Interview Round: Other

What is the `log-sum-exp` trick, and why is it needed when maximizing a log-likelihood numerically? ```hint Check the floating-point range Work out what `exp(800)` and `exp(-800)` evaluate to in double precision, and what a log of the result gives you. ``` ```hint Where the sums come from List the likelihoods where a log is applied to a sum of exponentials: softmax outputs, mixture densities, and sums over latent states. ``` ### What a Strong Answer Covers - The identity behind the trick and why it keeps every exponent in a safe range. - How overflow and underflow arise in double precision, with rough limits for `exp`. - Where sums of exponentials appear in likelihood work (softmax, mixtures, EM, HMM forward pass). - What happens to a numerical optimizer when the objective or its gradient becomes `inf` or `nan`. - Edge cases such as every input being `-inf`, and computing along one axis of a batch. ### Follow-up Questions - How do you compute log-softmax and its gradient stably, and how is that gradient related to log-sum-exp? - In an HMM forward pass, what is the alternative to working in log-space, and when would you choose it? - Why does subtracting the mean of the inputs not give the same guarantee as subtracting the maximum?

Overview: Asks what the log-sum-exp trick computes and why numerical maximum likelihood needs it. Tests your understanding of floating-point overflow and underflow, where sums of exponentials appear in softmax, mixture and latent-variable likelihoods, and how a single bad value breaks an optimizer.

General logo
General
Nov 25, 2026
mediumData ScientistOtherStatistics & Math
0
0

What is the log-sum-exp trick, and why is it needed when maximizing a log-likelihood numerically?

What a Strong Answer Covers Guidance

  • The identity behind the trick and why it keeps every exponent in a safe range.
  • How overflow and underflow arise in double precision, with rough limits for exp .
  • Where sums of exponentials appear in likelihood work (softmax, mixtures, EM, HMM forward pass).
  • What happens to a numerical optimizer when the objective or its gradient becomes inf or nan .
  • Edge cases such as every input being -inf , and computing along one axis of a batch.

Follow-up Questions Guidance

  • How do you compute log-softmax and its gradient stably, and how is that gradient related to log-sum-exp?
  • In an HMM forward pass, what is the alternative to working in log-space, and when would you choose it?
  • Why does subtracting the mean of the inputs not give the same guarantee as subtracting the maximum?