Cross-entropy is the negative log-likelihood
probability▲▲△All values rounded to 4 d.p. Logarithms are natural, so losses are in nats.
STATEMENT
Show that binary cross-entropy and the negative log-likelihood of a Bernoulli model are the same quantity, then evaluate both at for each possible label.
GIVEN
A model that outputs a single number , interpreted as . The label . Binary cross-entropy is defined as
and the Bernoulli likelihood of the observed label is .
FIND
An algebraic demonstration that , and the value of each at and .
STRATEGY
Take the logarithm of the likelihood and let the exponents come down. The two expressions are then identical term for term, so this is an identity rather than an approximation — which matters, because it means choosing cross-entropy is choosing a Bernoulli noise model, whether or not anyone said so.
SOLUTION
Step 1 — write the likelihood. The trick is the indicator exponent: since is or , exactly one of the two factors survives.
Check both cases before going further. At : . At : . Correct in both.
Step 2 — take logarithms. Using and :
Step 3 — negate.
-\log P(Y = y) = -\big[\,y\log p + (1-y)\log(1-p)\,\big] = \mathrm{CE}(p,y) \tag{I.1.6}
The two definitions coincide exactly, for every and every . Nothing was approximated and no assumption was added beyond the one already made when the output was called a probability.
Step 4 — evaluate at . The term vanishes:
and independently, . They agree.
Step 5 — evaluate at . Now the term vanishes:
and .
The asymmetry is the point. The same prediction costs when it is right and when it is wrong — seven times as much. A model is punished far more for confident error than it is rewarded for confident correctness, and that asymmetry is what drives calibration.
Answer
In bits, divide by : and bits respectively.
Check — numeric · i-1-b04-bernoulli-cross-entropy.py
def cross_entropy(p, y): return -(y * log(p) + (1 - y) * log(1 - p))
def likelihood(p, y): return p if y == 1 else 1 - p
ce, nll = cross_entropy(p, y), -log(likelihood(p, y))The two are computed from separate definitions and compared, rather than one
being derived from the other. It prints equal=True at every tested pair.
Executed in CI. The digits above are the digits it printed.
Check — sanity
A perfect prediction costs nothing. At with , . The snippet’s row gives , which is close to zero and on the right side of it.
A maximally uncertain prediction costs . At the loss is nats bit, for either label. One bit is exactly the information in a fair coin (Entropy 0.IT.01), so the units are behaving.
The two branches sum correctly. For any , the expected cross-entropy under the model’s own distribution is , which is the entropy of that Bernoulli. At : nats, and the closed-form entropy of is . That is a genuinely independent route to the same number.
Where this breaks
The identity needs strictly. At with the loss is : a model that assigns zero probability to something that then happens is infinitely wrong, and no finite gradient step recovers from it. This is not a corner case in practice — it is why the loss is computed from logits with the log-sum-exp identity (Log-sum-exp 0.NU.02) rather than from a probability that a float can round to exactly or .
Variation
Extend to classes: show that categorical cross-entropy is the negative log-likelihood of a categorical distribution, and evaluate for with the true class being the second.