Pro
Pro lesson

Softmax and cross-entropy

How a model turns raw scores into probabilities, and the loss that tells it how wrong it was.

This one’s part of How Models Learn Pro — every lesson, every interactive, and new ones as they land. About 11 minutes.

Already Pro? Sign in and you’ll go straight in.

Inside “Softmax and cross-entropy”

What you’ll learn

  1. From scores to probabilities
  2. Why exponentials?
  3. Temperature
  4. Logarithms measure surprise
  5. Cross-entropy: the loss for classifiers
  6. What language models minimise

Key terms

Logit
A raw score a model gives one class before softmax; it can be any number, positive or negative.
Softmax
Turns a list of scores into positive weights that add up to 1 (probabilities): take exp of each score and divide by the total. A score one point higher than another gets about 2.7 times its weight, so large gaps in score become very large gaps in weight.
Temperature
A number T that every score is divided by before softmax; below 1 sharpens the probabilities, above 1 flattens them.
Natural logarithm (ln)
The logarithm with base e ≈ 2.718: ln y is the power you raise e to in order to get y.
Surprise
How unexpected an outcome was, −ln p for an outcome given probability p; also called self-information.
Nat
The unit of surprise or cross-entropy when natural logs are used; logs base 2 give bits instead.
Cross-entropy loss
For one example, −ln of the probability the model gave the correct answer; also called log-loss.
Perplexity
exp of a language model’s average cross-entropy (in nats) per token; lower means less surprised by the text.

Sources