AI Foundations for Developers COURSE·LESSON 05 OF 410 completed

Probability, Entropy, and Uncertainty

Conditional probability is the key idea

P(A | B) means the probability of A given B. A language model estimates a distribution for a next token given a preceding sequence. It is not directly estimating whether an entire answer is factually correct.

For a simple illustration, a model might assign P(cat)=0.6, P(dog)=0.3, P(bird)=0.1. These probabilities sum to one. The most likely token is cat, but that does not mean the model has verified that an image actually contains a cat.

Independence means knowing one event does not change the probability of another. Natural language tokens are strongly dependent. Treating “not good” as unrelated occurrences of “not” and “good” can lose the meaning of the phrase.

Base rates change conclusions

Imagine a rare event affecting 1 in 100 tickets. A detector catches 90% of those events but incorrectly flags 10% of ordinary tickets. In 1,000 tickets, it detects about 9 true cases and flags about 99 ordinary tickets. Only 9/108 ≈ 8.3% of alerts are true positives. High sensitivity does not automatically produce trustworthy alerts when the event is rare.

Entropy and cross-entropy

Entropy measures uncertainty in a distribution: H(p) = -Σ p(x) log p(x). A distribution concentrated on one outcome has lower entropy than a uniform distribution. The logarithm base determines units; base two gives bits.

Cross-entropy scores predictions against target outcomes. For a known correct class with probability p, the negative log-likelihood is -log(p). Assigning 0.9 to the correct class incurs less loss than assigning 0.1. It also strongly penalizes confident errors.

python
import math

for p in [0.9, 0.5, 0.1]:
    print(p, round(-math.log(p), 3))
# 0.9 0.105
# 0.5 0.693
# 0.1 2.303

Try it in the Python compiler. A probability of zero would make the log undefined; real implementations use numerically stable formulations.

Calibration versus self-reported confidence

A calibrated classifier's 80% predictions should be correct about 80% of the time over comparable examples. Calibration must be measured. A generated sentence saying “I am 95% certain” is text, not a validated calibration guarantee.

Checkpoint with answers

Can lower entropy mean greater correctness? No. A system can be confidently wrong.

What is the loss when the correct class gets probability 0.5? About 0.693 with natural logarithms.

Why do rare-event detectors need precision measurements? Because false positives from the large ordinary population can outnumber real detections.

Learn at your own pace0 / 41 lessons complete