Self-Information and Bits

Derive logarithmic surprise from probability, compare bits and nats, interpret fractional ideal code lengths, handle zero-probability failures, and add conditional costs across sequences.

Self-information measures the surprise of one observed outcome relative to a stated probability model. A likely outcome carries little new information when it occurs; an unlikely outcome carries more. The logarithm makes independent information additive and gives the quantity an operational interpretation as an ideal code length.

Surprise Depends on Probability

Suppose an outcome xx has probability p(x)p(x). Its self-information, also called surprisal, is

I(x)=logbp(x).I(x)=-\log_b p(x).

“The information in outcome x is negative log base b of the probability of x.” A smaller probability produces greater information because its logarithm is more negative before the minus sign is applied.

Three boundary behaviors agree with ordinary reasoning about surprise:

  • if p(x)=1p(x)=1, then I(x)=0I(x)=0 because the outcome was certain;
  • if 0<p(x)<10<p(x)<1, then I(x)>0I(x)>0;
  • as p(x)p(x) approaches zero, I(x)I(x) grows without bound.

For a weather model with p(rain)=0.2p(\text{rain})=0.2, observing rain carries

log2(0.2)2.322 bits.-\log_2(0.2)\approx2.322\text{ bits}.

Observing no rain under the same model carries

log2(0.8)0.322 bits.-\log_2(0.8)\approx0.322\text{ bits}.

Rain is more informative in this technical sense because the model considered it less likely. This statement depends on the model and does not say that rain is more important to every person or decision.

Exercise: Find the information in a certain event

How many bits of self-information does an event with probability 11 carry?

Compute it first, then check your number.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintUse log base two

Calculate log21-\log_2 1.

SolutionCertainty carries zero surprise

Since log21=0\log_2 1=0, a certain event carries 00 bits of self-information. Observing it resolves no uncertainty left by the model.

Why Information Uses a Logarithm

A useful numerical measure of surprise should behave in three ways:

  1. it should vary continuously as probability changes;
  2. a less probable outcome should carry more information; and
  3. independent outcomes should have additive information.

For independent outcomes xx and yy, p(x,y)=p(x)p(y)p(x,y)=p(x)p(y). A logarithm converts this product into a sum:

I(x,y)=logb[p(x)p(y)]=logbp(x)logbp(y)=I(x)+I(y).\begin{aligned} I(x,y) &=-\log_b[p(x)p(y)]\\ &=-\log_b p(x)-\log_b p(y)\\ &=I(x)+I(y). \end{aligned}

Under mild regularity conditions, these requirements lead to a negative logarithm up to a positive choice of scale. The logarithm is therefore not an arbitrary decoration added to probability: it expresses how independent possibilities combine.

Two independent fair coin results have joint probability 1/41/4. Their information is log2(1/4)=2-\log_2(1/4)=2 bits, equal to one bit for each result. Ten independent fair coin results similarly carry ten bits.

Exercise: Add information across independent events

Two independent outcomes have probabilities 1/41/4 and 1/81/8. How many bits of self-information does the pair carry?

Compute it first, then check your number.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintAdd the two surprisals

The outcomes carry 22 bits and 33 bits separately.

SolutionIndependent surprisals add

The joint probability is (1/4)(1/8)=1/32(1/4)(1/8)=1/32, so the pair carries log2(1/32)=5-\log_2(1/32)=5 bits. Equivalently, add the separate costs: 2+3=52+3=5 bits.

The Logarithm Base Sets the Unit

With base 22, information is measured in bits. Each bit corresponds to one binary distinction in an ideal description. With base ee, the unit is the nat. Base 1010 gives hartleys.

ProbabilityInformation in bitsInformation in nats
110000
1/21/211ln20.693\ln2\approx0.693
1/41/422ln41.386\ln4\approx1.386
1/81/833ln82.079\ln8\approx2.079

The units are converted by a constant factor:

Ibits(x)=Inats(x)ln2.I_{\text{bits}}(x)=\frac{I_{\text{nats}}(x)}{\ln2}.

Halving a probability always adds one bit:

log2(p2)=log2p+1.-\log_2\left(\frac{p}{2}\right)=-\log_2p+1.

An equation or loss reported without its logarithm base may still be useful, but its numerical unit is incomplete. Many mathematical and machine-learning libraries use natural logarithms, so their log losses are measured in nats unless converted.

Exercise: Calculate a rare outcome's information

An outcome has probability 1/161/16. How many bits of self-information does it carry?

Compute it first, then check your number.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintWrite the probability as a power of two

1/16=241/16=2^{-4}.

SolutionThe outcome carries four bits

Since 1/16=241/16=2^{-4}, I(x)=log2(24)=4I(x)=-\log_2(2^{-4})=4 bits. Four binary distinctions can identify one outcome among sixteen equally likely possibilities.

Ideal Code Length May Be Fractional

The probability p(x)=0.3p(x)=0.3 gives

I(x)=log2(0.3)1.737 bits.I(x)=-\log_2(0.3)\approx1.737\text{ bits}.

An isolated binary codeword cannot literally contain 1.7371.737 bits. The value is an ideal length. Prefix-free codes for individual symbols use whole-number lengths, while block codes and arithmetic coding can approach fractional average lengths over long sequences.

For example, a sequence of 100100 occurrences of outcomes that each receive probability 0.30.3 has ideal total length

100[log2(0.3)]173.7 bits.100[-\log_2(0.3)]\approx173.7\text{ bits}.

The sequence can use a whole number of bits while its average approaches 1.7371.737 bits per outcome. Information theory commonly makes statements about long-run or expected length rather than promising an exact fractional codeword for one symbol.

A Model Assigns the Surprise

Self-information is not a property of an outcome by itself. It is calculated from a probability distribution. If model qAq_A assigns probability 0.80.8 to an observed token, its cost is

log2(0.8)0.322 bits.-\log_2(0.8)\approx0.322\text{ bits}.

If model qBq_B assigns probability 0.10.1 to the same observed token, its cost is

log2(0.1)3.322 bits.-\log_2(0.1)\approx3.322\text{ bits}.

Model B pays three extra bits for that outcome. A model is therefore penalized strongly when it assigns little probability to what occurs. This is the local, one-outcome form of logarithmic loss.

Convert probabilities to ideal bit lengths

Change the probabilities and compare how rapidly code length grows near zero. Every value must lie strictly between zero and one.

Ready to run.

Exercise: Compare two predictive costs

Model A assigns probability 1/21/2 to the observed outcome. Model B assigns probability 1/81/8. How many more bits does model B use for that outcome?

Compute it first, then check your number.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintCalculate both surprisals

Compare log2(1/2)-\log_2(1/2) with log2(1/8)-\log_2(1/8).

SolutionThe lower probability costs two extra bits

Model A pays 11 bit and model B pays 33 bits. Model B therefore pays 31=23-1=2 additional bits for the observed outcome.

Zero Probability Creates Infinite Loss

If a model assigns q(x)=0q(x)=0 to an outcome that occurs, then

logq(x)=+.-\log q(x)=+\infty.

The issue is not merely numerical. A zero probability says that the event is impossible under the model, so a code based on that model has not reserved a finite representation for it. In practice, probabilistic systems must handle support carefully. Smoothing, probability floors, or model structures with positive probability can prevent unintended zeros, although each choice changes the model and must be justified.

A zero-probability outcome under the true source distribution is different: it never occurs under that source and therefore contributes nothing to an average over source outcomes. Problems arise when the source can produce an outcome to which the predictive model assigns zero.

Exercise: Recognize a support failure

A source can produce symbol CC with positive probability, but a predictive model assigns q(C)=0q(C)=0. What logarithmic cost does the model incur when CC occurs?

Choose the cost

Select one choice, then check.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintApproach zero from above

As q(C)q(C) becomes smaller and positive, logq(C)-\log q(C) grows without bound.

SolutionAn observed zero-probability event has infinite log cost

The cost is logq(C)=log0=+-\log q(C)=-\log0=+\infty in the limiting sense. The model's support fails to include an outcome that the source can produce.

Sequence Information Uses Conditional Probabilities

Independence is not required to calculate the information in a sequence. The probability chain rule writes

p(x1,x2,,xn)=t=1np(xtx1,,xt1).p(x_1,x_2,\ldots,x_n) =\prod_{t=1}^{n}p(x_t\mid x_1,\ldots,x_{t-1}).

Taking a negative logarithm turns the product into a sum:

log2p(x1,,xn)=t=1nlog2p(xtx<t).-\log_2p(x_1,\ldots,x_n) =\sum_{t=1}^{n}-\log_2p(x_t\mid x_{<t}).

“The information in the whole sequence is the sum, over positions t, of the negative log probability of the observed symbol given the preceding symbols.” The notation x<tx_{<t} means all sequence elements before position tt.

Suppose a model assigns

p(the)=12,p(catthe)=14,p(satthe cat)=18.p(\text{the})=\frac12,\qquad p(\text{cat}\mid\text{the})=\frac14,\qquad p(\text{sat}\mid\text{the cat})=\frac18.

The sequence probability is (1/2)(1/4)(1/8)=1/64(1/2)(1/4)(1/8)=1/64. Its information is

log2(1/64)=6 bits,-\log_2(1/64)=6\text{ bits},

which also equals 1+2+31+2+3 bits from the three conditional predictions. This additive token-level form is the basis of autoregressive language-model log loss.

One Outcome and an Average Are Different

Self-information describes one realized outcome under a stated model. It does not measure semantic meaning, practical importance, truth, or usefulness. A random identifier may be highly surprising yet convey little useful structure, while a predictable warning may be extremely important to act upon.

Before observing an outcome, we can average its possible self-information values using their source probabilities. That expected surprise is entropy, the subject of the next lesson. Keeping the distinction clear prevents us from calling the surprise of one rare event “the entropy” and from confusing a model's local log loss with the source's average uncertainty.

Exercise: Distinguish surprisal from entropy

Which quantity describes the information in one observed outcome under a stated probability model?

Choose one

Select one choice, then check.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintOne outcome versus an expectation

Entropy is the source-probability-weighted average of the possible self-information values.

SolutionSelf-information belongs to one outcome

Self-information logp(x)-\log p(x) describes one observed outcome relative to a model. Entropy is the expected self-information over all outcomes under a source distribution.

Review

Not marked done.