CrackML by @ml.with.umang
Interview questions / ML Math
ML Math interview question

Derive Binary Cross-Entropy

Derive the binary cross-entropy loss from a Bernoulli likelihood.

mediumconceptEvidence 41/1001 source reportLinkedIn

The 60-second answer

Model y∈{0,1} as Bernoulli with predicted probability p: P(y|p)=p^y(1-p)^(1-y). Take the log likelihood, then negate it to obtain L=−[y log p +(1−y) log(1−p)].

Build the answer in this order

1
Start with intuition

Model y∈{0,1} as Bernoulli with predicted probability p: P(y|p)=p^y(1-p)^(1-y).

2
Write the mathematical object

Take the log likelihood, then negate it to obtain L=−[y log p +(1−y) log(1−p)].

3
State assumptions

Explain why minimizing negative log likelihood is equivalent to maximum likelihood estimation over independent examples.

4
Connect back to ML behavior

Connect logits to the numerically stable implementation: use log-sum-exp/BCE-with-logits instead of manually applying sigmoid then log.

A useful interview mental model

This is the shape of a strong answer—not a script to memorize.

01Definition
02Mechanism
03Trade-offs
04Failure modes
05When to use

Senior-level signal

  • Senior answers can derive the gradient with respect to the logit and show the elegant p−y result.
  • Discuss class weighting/focal loss as objective changes, not merely metric tweaks.

What the interviewer is really testing

Whether you can connect the math to optimization, uncertainty, model behavior, and a practical engineering decision.

Likely follow-up questions

What assumption makes this approach work?
When would you choose the strongest alternative instead?
What production or data failure mode changes your answer?

Common weak-answer patterns

  • Reciting a definition without mechanism or assumptions.
  • Claiming one technique is always better without a data regime.
  • Stopping before failure modes, validation, or deployment implications.