Write binary cross-entropy for probability p̂ and label y ∈ {0, 1}.
easyAnswer
- L(y, p̂) = -[y*log(p̂) + (1-y)*log(1-p̂)].
- Comes from the negative log-likelihood of a Bernoulli.
- Always non-negative, zero iff p̂=y ∈ {0,1}.
- In practice, apply the numerically-stable BCEWithLogitsLoss (input is logits, sigmoid + BCE fused with log-sum-exp for stability) — never compute sigmoid then log separately in fp16.
Check yourself — multiple choice
- L = -[y·log(p̂) + (1-y)·log(1-p̂)] — NLL of Bernoulli; use BCEWithLogits for stability
- L = y · p̂
- L = |y - p̂|
BCE = -[y·log(p̂) + (1-y)·log(1-p̂)]; combine with logits for numerical stability.
#losses
Practise Deep Learning
214 interview questions in this topic.
Related questions
- Why compute softmax + cross-entropy jointly via log-sum-exp?
- How should the output head be designed for a regression task with a strictly positive target?
- How is the output head different for multi-label vs multi-class classification?
- What is label smoothing and why does it help?
- How does YOLO / SSD / RetinaNet differ from two-stage detection?
- Briefly, what do BLEU and ROUGE measure?