The learning path

Step 5 of 29 · Module 2: Math Foundations

Math · Beginner

Probability, Softmax, and Cross-Entropy

8 min read Updated Jul 2026

You've already used the central idea of this lesson without it being named: every time a model picked its "next word," and every time the attention lesson blended words by their attention weights, that was probability at work. This lesson names it properly and covers the one formula — cross- entropy — that every model on this site was actually trained to minimize.

What a probability distribution is

A is just a set of numbers — one per possible outcome — that satisfy two rules: every number is zero or positive, and they all add up to exactly 1. That's the entire mathematical definition. "91% chance the next word is Paris" is one entry in a distribution over every word in the model's vocabulary.

Softmax, precisely

You met in the attention lesson as the step that turned raw attention scores into weights. It's a general tool for turning any list of raw numbers into a valid probability distribution:

softmax of a vector of scores
softmax(x)_i = e^(x_i) / Σ e^(x_j)

In words: exponentiate every number (which guarantees it's positive), then divide each one by the sum of all the exponentiated numbers (which guarantees they add to 1). This is the exact same operation used twice on this site already — once to turn attention scores into weights, and once, in the Mixture of Experts lesson, to turn router scores into a probability of using each expert.

Cross-entropy — what training actually minimizes

Every time this site has said a model is "trained until its predictions get better," there is a precise number being measured and reduced: .

cross-entropy loss for one prediction
L = −log( p_correct )

Where p_correct is the probability the model assigned to the actual correct next word. If the model was confident and right — say p_correct = 0.9 — the loss is small (−log(0.9) ≈ 0.105). If it was confident and wrong p_correct = 0.01 for the actual answer — the loss is large (−log(0.01) ≈ 4.6). This is the exact shape you want: confident correct answers are barely penalized, confident wrong answers are penalized heavily.

"Training" is: run the model forward, compute this loss, compute its gradient (the previous lesson) with respect to every parameter, and take a small step to reduce it (the next lesson). Repeat that loop billions of times over enormous amounts of text, and you get a model whose probability distributions keep getting closer to reality.

Bayes' theorem, briefly

One more idea worth having, even though it shows up less directly in day-to-day model training: describes how to update a belief given new evidence.

Bayes' theorem
P(A | B) = P(B | A) · P(A) / P(B)

In plain terms: the probability of A given you've observed B depends on how likely B is if A were true, weighted by how likely A was to begin with. It underlies a lot of classical machine learning (covered in the next stage of this path) and is a useful mental model even outside AI — for reasoning about how much any single piece of evidence should actually shift your beliefs.

Quick knowledge check

1. What two properties must every probability distribution satisfy?

2. What does softmax do to a list of raw scores?

3. Why does cross-entropy loss penalize a confident wrong answer heavily?

Spot something wrong, outdated, or confusing?

Suggest an edit
Gradient Descent: How Models Actually LearnContinue