1. What does a “70% chance of rain” mean?
The weather forecast says: “There is a 70% chance of rain tomorrow.” But tomorrow it will either rain or it will not. Where does that 70% come from?
One way to understand a well-calibrated forecast is through long-run frequency: among many comparable situations assigned a 70% probability, rain should occur about seven times out of ten. The number is not a promise about one particular day, and it does not mean that it will rain for 70% of the day.
Rolling a die gives another example. Suppose you roll it 1,000 times and get a three on 168 rolls. The observed frequency is:
That is an estimate of the probability, not an exact law. For a fair six-sided die, the theoretical probability is ; observed frequencies approach it as the number of independent rolls grows.
Often we care about more than one outcome: what proportion belongs to each possible outcome? This question appears repeatedly in AI. Give a language model the prompt “The weather today is …”, and it can assign a probability to every candidate next token rather than simply returning one answer.
This collection of numbers must obey two rules:
A proportion cannot be negative, and the probabilities of all mutually exclusive, exhaustive outcomes add up to one. A collection satisfying these rules is a discrete probability distribution: a complete description of how probability is allocated across the possible outcomes.
This explains why a classifier's final outputs, or a language model's next-token predictions, can be called probabilities. They form a non-negative distribution that sums to one. The raw scores inside a network do not necessarily have these properties; Softmax, in Lesson 11, turns scores into this form. Not every neural network outputs probabilities, and a valid distribution does not by itself guarantee accurate predictions.
2. Information: surprising news carries more
Once we have probabilities, a new question appears: how much information does a message carry? Start with two pieces of news from a friend:
- “The sun will rise in the east tomorrow.” You barely react: it tells you almost nothing new.
- “The owner of the corner shop won five million in the lottery last night.” That gets your attention.
The first event is almost certain; the second is rare. The less expected an event is, the more information observing it gives you. This is a central intuition of information theory.
The self-information, or surprisal, of an outcome is:
Why a negative logarithm? It decreases as probability increases, but it also has another useful property: information from independent messages adds up. Independent probabilities multiply, while logarithms turn multiplication into addition.
Using logarithms with base two, try three examples:
- A certain event, : bits. No surprise, no new information.
- One outcome of a fair coin toss, : bit.
- A rare event, : bits.
With base-two logarithms, the unit is the bit. It relates to how many binary decisions are needed to distinguish outcomes, and to efficient average encoding lengths. An individual information value can be fractional; it is not necessarily the literal length of one binary message.
Deep learning usually uses the natural logarithm, written , with base . Its unit is the nat. The two choices differ only by a fixed scale:
The underlying properties stay the same. If an event is assigned zero probability, its information is infinite in the limiting sense: the distribution considers that observation impossible.
3. Entropy: how difficult is the whole distribution to predict?
Information describes the surprise of one specific outcome. To describe how unpredictable the whole situation is, take a weighted average of the possible surprises, using each outcome's probability as its weight.
This average surprise is entropy:
Compare two coins to build an intuition.
For a fair coin, heads and tails each have probability :
For a biased coin with probabilities and :
The fair coin is harder to predict. With the biased coin, guessing heads is usually right, so the average uncertainty is lower.
For a fixed set of possible outcomes:
- The uniform distribution has the greatest entropy: . Every outcome is equally likely.
- A deterministic distribution, with one outcome having probability one, has entropy zero. There is no uncertainty.
In an entropy sum, we use the convention , justified by the limit as the probability approaches zero. Outcomes that never occur contribute nothing to the average.
This helps explain why predicting language is a meaningful task. If every token were equally likely regardless of context, a model could not use context to predict better than uniform guessing. Real language has structure: “nice” is more plausible than “table” after “The weather today is …”. There is enough regularity to make prediction and compression possible, while several continuations may still make sense. It is neither completely predetermined nor completely random.
4. Cross-entropy: using a possibly inaccurate map
Entropy measures how unpredictable the true distribution is. In AI, we often have only a map drawn by the model: its estimated distribution , which may differ from the true distribution .
How surprised will we be on average if we use the model's map to face the real world?
The answer is cross-entropy. Measure surprise using the model's probabilities, , but average it using the true probabilities :
For one next-token training example, the observed correct answer is known: suppose it is “cat”. We represent that target with a one-hot distribution:
The model is less certain. Suppose its predictions are:
Only the cat term has a non-zero target weight. All the other terms disappear, leaving:
More generally, if the correct label is , the per-example loss is:
The more confidently the model assigns probability to the correct answer, the closer is to one and the closer the loss is to zero. If it assigns almost no probability to the correct answer, the loss becomes very large.
That makes cross-entropy a natural measure of how badly a next-token prediction went wrong. Lesson 10: Loss functions will use it as a training objective. The formula has an information-theoretic meaning rather than being an arbitrary scoring rule.
The one-hot target describes the observed answer for this example. It does not mean that only one continuation is ever possible in the real language distribution. Training averages losses over many examples.
Two additional intuitions
Cross-entropy is at least as large as entropy. The extra part measures the mismatch between the model's map and the true distribution. It is called Kullback–Leibler divergence, or KL divergence:
For a finite discrete distribution, the lower bound is reached when . If for an outcome with , cross-entropy is infinite. KL divergence measures a discrepancy, but is not a symmetric distance: exchanging and generally changes its value.
Why use a logarithmic penalty instead of a simple difference? As the model's probability for the correct answer approaches zero, grows without bound. Its derivative with respect to that probability is:
This gives a strong penalty for confidently missing the correct answer. Connect this to the previous lesson: gradients tell us how changing a quantity changes the loss.
There is a useful distinction here: this derivative is with respect to a probability, not directly to a network's parameters. With Softmax and cross-entropy, the derivative with respect to a raw score simplifies to , which stays bounded. The full training gradient also depends on the network. We will return to this connection in the lessons on Softmax and backpropagation.
Squared-error losses do not grow without bound as a correct-answer probability approaches zero. When combined with saturating probability outputs, their gradients can also become weak. This does not make squared error universally unsuitable; it helps explain why cross-entropy is a standard choice for classification and next-token prediction.
5. What you have discovered
A probability distribution allocates probability across all possible outcomes: its entries are non-negative and sum to one.
Information measures how surprising one outcome is. Entropy is the whole distribution's average surprise. Cross-entropy is the average surprise when we use the model's distribution while outcomes follow .
- Distribution: and . Probability allocated across outcomes.
- Information: . Surprise of one outcome.
- Entropy: . Average surprise under the true distribution.
- Cross-entropy: . Average surprise using the model's probabilities.
- KL divergence: . Extra cost of a mismatched distribution.
For a one-hot target, cross-entropy reduces to the negative logarithm of the model's probability for the correct answer. That is the connection between information theory and the loss functions used to train classifiers and language models.
You now have four foundational tools: vectors, matrices, gradients and probabilities. The next chapter will bring them together in a neuron: the basic building block of a neural network.