Information Theory

August 2026Vladislav Kruglikov

Surprise is the single event quantity. Entropy averages it under the true distribution. Cross entropy averages it using the probabilities of the model. KL is the extra cost of using the model. Negative log likelihood and binary cross entropy are the forms this takes for particular observations and distributions.

Requirements for a surprise function

Start with one event xx. Suppose we know its probability p(x)p(x), and we want a number that says how surprising it is to see that event happen.

So we want a function from probability to surprise. If the event has probability p(x)p(x), write its surprise as S(p(x))S(p(x)).

The function should satisfy three basic requirements.

First, rarer events should be more surprising. If x1x_1 is less likely than x2x_2, then seeing x1x_1 should carry more surprise:

p(x1)<p(x2)    S(p(x1))>S(p(x2))p(x_1) < p(x_2) \implies S(p(x_1)) > S(p(x_2))

Second, independent surprises should add. If two independent events happen together, their joint probability is the product of their probabilities:

p(x,y)=p(x)p(y)p(x, y) = p(x)p(y)

The surprise of seeing both should be the surprise of seeing one plus the surprise of seeing the other:

S(p(x,y))=S(p(x))+S(p(y))S(p(x, y)) = S(p(x)) + S(p(y))

Third, the function should be continuous. A tiny change in probability should not create a sudden jump in surprise.

These requirements are already very restrictive. They say surprise should decrease as probability increases, turn multiplication of independent probabilities into addition of surprises, and behave smoothly.

Finding a function that satisfies these requirements

The second requirement is the important one. For independent events, probabilities multiply:

p(x,y)=p(x)p(y)p(x, y) = p(x)p(y)

But surprises should add:

S(p(x,y))=S(p(x))+S(p(y))S(p(x, y)) = S(p(x)) + S(p(y))

So the surprise function has to turn multiplication into addition:

S(ab)=S(a)+S(b)S(ab) = S(a) + S(b)

That is exactly what logarithms do:

log(ab)=loga+logb\log(ab) = \log a + \log b

Continuity rules out strange discontinuous functions that satisfy the same algebraic identity but do not behave like a measurement. So the surprise function must be a constant multiple of a logarithm:

S(p)=klogpS(p) = k\log p

Probabilities are between 0 and 1, so logp\log p is non-positive. But surprise should be non-negative, and rarer events should have larger surprise. That fixes the sign:

S(p)=klogpS(p) = -k\log p

The constant kk must be positive and only chooses the unit. If we choose base 2 and set k=1k = 1, surprise is measured in bits:

S(p)=log2pS(p) = -\log_2 p

Entropy as average surprise across a distribution

Surprise belongs to an event after it happens. But before sampling from a distribution, we can still ask how surprised we expect to be.

Suppose XX is sampled from a distribution pp. If the outcome is xx, its surprise is:

log2p(x)-\log_2 p(x)

But outcome xx happens with probability p(x)p(x). So the expected surprise is the weighted average of all possible surprises:

H(X)=E[S(p(X))]H(X) = \mathbb{E}[S(p(X))]

Substituting the surprise function gives:

H(X)=xp(x)(log2p(x))H(X) = \sum_x p(x)(-\log_2 p(x))

or equivalently:

H(X)=xp(x)log2p(x)H(X) = -\sum_x p(x)\log_2 p(x)

This expected surprise is the entropy of the distribution:

Low entropyHigh entropy

A low entropy distribution is concentrated on a few outcomes whereas a high entropy distribution tends to be more uniform.

Cross entropy as expected surprise using another distribution

Entropy assumes the probabilities used to measure surprise are the same probabilities that generate the data. If the true distribution is pp, then outcome xx has surprise log2p(x)-\log_2 p(x), and the average surprise is:

H(p)=xp(x)log2p(x)H(p) = -\sum_x p(x)\log_2 p(x)

But a model usually does not know pp. It has its own distribution qq. If the world still samples outcomes from pp, but the model measures surprise using qq, then the surprise of outcome xx becomes:

log2q(x)-\log_2 q(x)

The average is still taken over what actually happens, so outcomes are weighted by p(x)p(x):

H(p,q)=xp(x)log2q(x)H(p, q) = -\sum_x p(x)\log_2 q(x)

This is cross-entropy. It is the expected surprise when reality follows pp, but the probabilities used to encode or predict it come from qq.

If q=pq = p, cross-entropy becomes ordinary entropy:

H(p,p)=H(p)H(p, p) = H(p)

If qq puts too little probability on events that actually happen, those events become overly surprising under the model, and cross-entropy increases.

KL divergence as extra surprise

Cross entropy tells us how surprised we are when reality follows pp, but we measure surprise using qq.

Entropy tells us how surprised we would be if we used the correct distribution pp.

So the extra surprise from using qq instead of pp is:

H(p,q)H(p)H(p, q) - H(p)

Now expand both terms:

H(p,q)H(p)=xp(x)log2q(x)+xp(x)log2p(x)H(p, q) - H(p) = -\sum_x p(x)\log_2 q(x) + \sum_x p(x)\log_2 p(x)

Combine the sums:

H(p,q)H(p)=xp(x)(log2p(x)log2q(x))H(p, q) - H(p) = \sum_x p(x)\left(\log_2 p(x) - \log_2 q(x)\right)

Use the logarithm rule:

H(p,q)H(p)=xp(x)log2p(x)q(x)H(p, q) - H(p) = \sum_x p(x)\log_2 \frac{p(x)}{q(x)}

This quantity is called the KL divergence from pp to qq:

DKL(pq)=xp(x)log2p(x)q(x)D_{\mathrm{KL}}(p \| q) = \sum_x p(x)\log_2 \frac{p(x)}{q(x)}

So cross entropy splits into two parts:

H(p,q)=H(p)+DKL(pq)H(p, q) = H(p) + D_{\mathrm{KL}}(p \| q)

The first part is the unavoidable surprise in the data. The second part is the extra surprise paid because the model distribution is not the true distribution.

Why minimizing cross entropy also minimizes KL divergence

The decomposition also explains why minimizing cross-entropy and minimizing KL divergence often mean the same thing in training.

Suppose pp is the data distribution and qq is the model distribution. The data distribution is fixed. The model can change qq, but it cannot change pp.

In:

H(p,q)=H(p)+DKL(pq)H(p, q) = H(p) + D_{\mathrm{KL}}(p \| q)

the entropy term H(p)H(p) does not depend on the model. It is an additive constant. So choosing the model that minimizes cross-entropy is the same as choosing the model that minimizes KL divergence from the data distribution to the model distribution:

argminqH(p,q)=argminqDKL(pq)\arg\min_q H(p, q) = \arg\min_q D_{\mathrm{KL}}(p \| q)

Cross entropy is the model-surprise view. KL divergence is the distribution-mismatch view. The optimization is the same because they differ only by the fixed entropy of the data.

Negative log likelihood as cross entropy with one hot targets

In classification, there is a small shift in what the distribution is over. Once an input xx is fixed, the model predicts a distribution over labels:

qθ(yx)q_\theta(y \mid x)

For example, the labels might be cat, dog, and horse. If the training label says the image is a cat, we usually define the target distribution as one-hot:

p(catx)=1p(\text{cat} \mid x) = 1 p(dogx)=0p(\text{dog} \mid x) = 0 p(horsex)=0p(\text{horse} \mid x) = 0

The cross-entropy for this one example is:

H(p(x),qθ(x))=yp(yx)logqθ(yx)H(p(\cdot \mid x), q_\theta(\cdot \mid x)) = -\sum_y p(y \mid x)\log q_\theta(y \mid x)

All labels except cat have weight zero, so their terms disappear:

H(p(x),qθ(x))=logqθ(catx)H(p(\cdot \mid x), q_\theta(\cdot \mid x)) = -\log q_\theta(\text{cat} \mid x)

So ordinary classification loss is still cross-entropy. We have just chosen a target distribution that puts all probability mass on the observed label.

Across a dataset, we average this model surprise over examples. Here xix_i is the input and yiy_i is its ground-truth label:

L(θ)=1Ni=1Nlogqθ(yixi)\mathcal{L}(\theta) = \frac{1}{N}\sum_{i=1}^N -\log q_\theta(y_i \mid x_i)

Soft labels fit the same formula. If an image is ambiguous, or if a teacher model gives probabilities, the target distribution does not have to put all mass on one class. Multiple labels can contribute to the same cross-entropy.

Thus, cross-entropy with one-hot targets is equivalent to negative log-likelihood.

Binary cross entropy as bernoulli negative log likelihood

Binary cross-entropy is cross-entropy for a binary target. If the model predicts p^=qθ(y=1x)\hat p = q_\theta(y = 1 \mid x), then the two-class model distribution is:

(p^,1p^)(\hat p, 1 - \hat p)

For a binary target yy, the target distribution is:

(y,1y)(y, 1 - y)

So binary cross-entropy is:

[ylogp^+(1y)log(1p^)]-\left[y\log \hat p + (1-y)\log(1-\hat p)\right]

With hard binary labels, where yy is either 0 or 1, BCE is also the NLL. With soft binary labels, BCE is still cross-entropy, but it is no longer one-hot NLL.