Availit World How AI really works, in your language

Lesson 7 of 4615 minFacts checked October 20, 2026

Probability: how models express doubt

A language model never knows the next word. It gives every possible token a chance, and then one is picked. Learn how those chances are made, how they are judged, and what “perplexity” means when a paper reports it.

In this lesson you will

  • Read a probability distribution, and pick from one at random
  • Turn a model’s raw scores into chances with softmax, by hand
  • See what temperature does to those chances
  • Understand the training loss as “surprise”, and what perplexity measures
On this page
  1. Chances between 0 and 1
  2. From scores to chances: softmax
  3. Temperature: confident or adventurous
  4. Surprise: how a model is graded
  5. Reading probability in papers
  6. Remember
  7. Check yourself

Chances between 0 and 1

A probability is a number from 0 to 1 that says how likely something is. 0 means it never happens, 1 means it always does, 0.25 means one time in four. A list of probabilities for every possible outcome, adding up to exactly 1, is a probability distribution.

This is what a language model produces at each step: a distribution over every token in its vocabulary, often more than 100,000 of them. For a prompt like “The capital of Pakistan is”, the distribution might look like this (illustrative numbers):

Chances for the next token (illustrative)
  • Islamabad 0.91
  • the 0.04
  • located 0.02
  • Karachi 0.01
  • every other token together 0.02

All the chances add up to 1. A real model spreads the last 2 % over more than 100,000 other tokens.

To sample from a distribution is to pick one outcome at random, with each outcome’s chance of being picked equal to its probability. Think of a spinning wheel where each token’s slice is as wide as its probability. Spin it, and “Islamabad” comes up 91 times in 100. That is how a chat model chooses its words.

Which of these lists could be a probability distribution?

0 of 6 sorted
  • [0.5, 0.5]

    Answer: Yes

  • [0.7, 0.2, 0.1]

    Answer: Yes

  • [0.6, 0.6]: adds up to 1.2

    Answer: No

  • [1.2, −0.2]: one value is negative

    Answer: No

  • [0.25, 0.25, 0.25, 0.25]

    Answer: Yes

  • [3.1, −1.2, 0.4]: a model’s raw scores

    Answer: No

From scores to chances: softmax

The last layer of a model does not output probabilities directly. It outputs one raw score per token, called a logit. Logits can be any number: 7.3, −2, 0.01. To turn them into a proper distribution, models use a function called softmax.

Softmax
p(token) = e^score ÷ (sum of e^score over all tokens)

Raise e (about 2.718) to the power of each score, then divide each result by the total.

scores [2.0, 1.0, 0.1]

Three tokens, say “blue”, “grey” and “green”.

e^scores = [7.39, 2.72, 1.11], total 11.21

Every result is positive, whatever the score was.

chances = [0.66, 0.24, 0.10]

Divide by the total. They now add up to 1.

Why the strange e to the power? Three good reasons. It makes every chance positive, even for negative scores. It turns differences into ratios: a token that scores 1 point higher is always about 2.7 times as likely, whatever the other scores are. And it keeps the order: the highest score always gets the highest chance.

Quick check

Two tokens have scores 3 and 3. What does softmax give them?

Show the answer

Answer: 0.5 each Equal scores give equal values of e^score, so each gets half of the total: 0.5 and 0.5.

Temperature: confident or adventurous

Before the softmax, the scores can be divided by a number called the temperature. It changes how sharp the distribution is, without changing which token is the favourite.

The same three scores [2.0, 1.0, 0.1] at three temperatures
TemperatureScores after dividingChances
0.5 (cooler)[4.0, 2.0, 0.2][0.86, 0.12, 0.02]
1 (as trained)[2.0, 1.0, 0.1][0.66, 0.24, 0.10]
2 (hotter)[1.0, 0.5, 0.05][0.50, 0.30, 0.19]

As the temperature falls towards 0, the top token’s chance approaches 1: the model always picks its favourite. This is called greedy decoding.

Try itTurn the temperature

The same idea, with a real-looking prompt. Lower the temperature and the favourite wins almost every time. Raise it and unlikely words start appearing.

This interactive part needs JavaScript.

Low temperatures suit tasks with one right answer, such as maths, code and facts. Higher temperatures suit brainstorming and stories, where variety helps. Reasoning models are usually not run at 0: their makers recommend temperatures from about 0.6 to 1, because a little variety helps long chains of thought. DeepSeek’s coding-agent results, for example, were measured at temperature 1.0. The full set of controls (top-k, top-p, min-p) has its own lesson in part 6.

Surprise: how a model is graded

Now the key to how language models learn. During training, the model reads real text and, at each position, gives a probability to the token that actually comes next. If it gave that token a high chance, it did well. If it gave it a tiny chance, it was surprised, and that surprise is the loss.

Surprise
surprise = −log(probability of the right token)

log is the natural logarithm. The minus sign makes the result positive.

How surprise grows as the chance shrinks
Chance given to the right tokenSurprise
10
0.50.69
0.251.39
0.12.30
0.014.61
0.0016.91

Every time the chance falls tenfold, the surprise rises by the same 2.30. Being confidently wrong is punished hard.

The average surprise over all the tokens in the training text is the cross-entropy loss, the number every pretraining run pushes down. Minimising it means one thing: give the text that really exists as high a probability as possible. Everything a model knows, it learned in the service of being less surprised.

Quick check

On some text, a model always gives the right next token a chance of 0.25. What is its perplexity?

Show the answer

Answer: 4 The surprise is −log(0.25) ≈ 1.39 for every token, and e^1.39 = 4. It is as unsure as a choice between 4 equal options.

Reading probability in papers

One more piece of notation, and you can read the opening equation of most language-model papers.

p(x_t | x_<t)

“The probability of token t, given all the tokens before it.” The bar | reads as “given”. This is what a language model computes.

p(text) = p(x₁) × p(x₂ | x₁) × p(x₃ | x₁, x₂) × …

The chance of a whole text is the chance of each token given the ones before, multiplied together.

loss = −(1/N) × Σ log p(x_t | x_<t)

Take logs and the product becomes a sum; Σ means “add up over all N tokens”. This is the cross-entropy loss from the last section.

Remember

  • A probability distribution gives every outcome a chance from 0 to 1, adding up to 1. A language model outputs one over its whole vocabulary at every step.
  • The model’s raw scores are logits. Softmax (e^score ÷ total) turns them into chances.
  • Temperature divides the scores first: lower is more predictable, higher is more varied, near 0 is greedy.
  • The training loss is cross-entropy: the average surprise, −log p, of the real next token. Perplexity = e^loss.
  • Papers write p(x_t | x_<t): the chance of the next token given everything before it.

Words to know

Probability
A number from 0 to 1 saying how likely something is.
Distribution
Chances for every possible outcome, adding up to 1.
Sampling
Picking an outcome at random, each with the chance its probability gives it.
Logit
A model’s raw score for a token, before softmax. Any number, positive or negative.
Softmax
The function that turns scores into a probability distribution: e^score divided by the total.
Temperature
A number the scores are divided by before softmax. Low is predictable, high is adventurous.
Greedy decoding
Always picking the single most likely token, as if the temperature were 0.
Cross-entropy loss
The average surprise of a model at the real next tokens. Pretraining pushes it down.
Perplexity
e to the power of the loss: how many equally likely choices the model is as unsure as.
Calibration
How well a model’s confidence matches how often it is actually right.

Go to the source

This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.

Check yourself

5 questions. Tap the answer you think is right.

0 of 5 answered

What must the chances in a probability distribution add up to?

Show the answer

Answer: 1 Something in the list must happen, so all the chances together add up to exactly 1.

What does softmax do?

Show the answer

Answer: Turns raw scores into chances that add up to 1 Softmax raises e to each score and divides by the total, giving a proper probability distribution. Picking a token is a separate step.

You lower the temperature from 1 to 0.3. What happens?

Show the answer

Answer: The favourite token becomes even more likely Dividing by a small number stretches the gaps between scores, so the top token gets a larger share. Its rank does not change.

A model gave the real next token a chance of 0.01. Is its loss on that token high or low?

Show the answer

Answer: High: it was very surprised Surprise is −log(0.01) ≈ 4.6, much higher than −log(0.9) ≈ 0.1 for a confident correct guess.

One model has a perplexity of 3 on some text, another 12. Which predicts the text better?

Show the answer

Answer: The one with 3 Lower perplexity means less surprise: the first model is as unsure as a choice among 3 tokens, the second among 12.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonBits and floats: how computers store numbers
Previous lesson All lessons

Choose your language