liveBook · Manning

Probability distribution

As explained in Build a Reasoning Model (From Scratch)

A normalized set of values over tokens that sum to 1 and can be sampled from to choose the next token.

A probability distribution converts temperature-scaled next-token logits into normalized scores between 0 and 1 whose total is 1. These scores represent relative confidence and provide the sampling basis for choosing the next token. section 4.4.3

Build the distribution during inference:

  • Scale the next-token logits by the selected temperature. section 4.4.3
  • Apply torch.softmax along the vocabulary dimension. section 4.4.3
  • Verify that the resulting probabilities sum to 1, then sample with torch.multinomial. section 4.4.3

Temperature changes the distribution

At temperature 5.0, the token " Berlin" has probability 0.0003. Lowering temperature to 0.5 raises it to 0.3398 and concentrates probability on fewer tokens; repeated sampling demonstrates the resulting frequency differences. section 4.4.3

Figure 4.10 Overview of the sampling process for generating tokens. Here, we focus on steps 3.3 and 3.4, where the next-token scores are converted into a probability distribution. The next token will be sampled based on that distribution.

Follow the inference workflow from rescaled logits through probability conversion to next-token sampling. section 4.4.3

How Build a Reasoning Model (From Scratch) covers it

How deep it goes
Defines normalization, verifies sums, visualizes scores, and demonstrates repeated sampling without deriving softmax internals.
Examples
Uses the Berlin token, probability plots, probability-sum checks, and repeated multinomial samples.
What it assumes
Assumes next-token logits and temperature scaling, then teaches their conversion into probabilities and samples.
What you can do after
Apply it via PyTorch to normalize logits, inspect probabilities, and sample one or many candidate tokens.
How it connects
Connects logits, temperature scaling, softmax, token sampling, and next-token generation.

Also explained in

Compare how 27 books explain probability distribution →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Reasoning Model (From Scratch). The section links point to the parts of the book it draws on.