Why does the cross-entropy loss include a logarithm?

Quick Overview

Asks why the cross-entropy loss used to train classifiers takes the logarithm of predicted probabilities. Tests your grasp of maximum likelihood, numerical stability, gradients through softmax, and what a proper scoring rule means for calibration.

Why does the cross-entropy loss include a logarithm?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Why does the cross-entropy loss include a logarithm? ```hint Start from the likelihood Write down the probability the model assigns to the whole training set and think about what you would optimize. ``` ```hint Look at the gradient For a softmax output, compare the gradient with respect to the logits with and without the log. ``` ### What a Strong Answer Covers - The link to maximum likelihood, and whether taking the log changes the optimum - What turning the product into a sum buys in practice - How the log changes the gradient through softmax or sigmoid - How the penalty behaves for confident wrong predictions, and what the log score implies for calibration - How to compute the loss stably in code ### Follow-up Questions - Why is mean squared error a poor loss for a sigmoid classifier? - How are cross-entropy and KL divergence related, and when does the difference between them matter? - What does label smoothing change in the cross-entropy target, and why would you use it? - How does focal loss modify cross-entropy, and when does it help?

Overview: Asks why the cross-entropy loss used to train classifiers takes the logarithm of predicted probabilities. Tests your grasp of maximum likelihood, numerical stability, gradients through softmax, and what a proper scoring rule means for calibration.

Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

Why does the cross-entropy loss include a logarithm?

What a Strong Answer Covers Guidance

  • The link to maximum likelihood, and whether taking the log changes the optimum
  • What turning the product into a sum buys in practice
  • How the log changes the gradient through softmax or sigmoid
  • How the penalty behaves for confident wrong predictions, and what the log score implies for calibration
  • How to compute the loss stably in code

Follow-up Questions Guidance

  • Why is mean squared error a poor loss for a sigmoid classifier?
  • How are cross-entropy and KL divergence related, and when does the difference between them matter?
  • What does label smoothing change in the cross-entropy target, and why would you use it?
  • How does focal loss modify cross-entropy, and when does it help?