EasyDeepLearn

Write binary cross-entropy for probability p̂ and label y ∈ {0, 1}.

easy

Answer

  • 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    p)2L\; = \;(y\; - \;p)^{2}
  • 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