liveBook · Manning

Softmax

As explained in Build a Reasoning Model (From Scratch)

A normalization function that converts logits into a probability distribution over possible next tokens.

Softmax converts rescaled next-token logits into probability scores so sampling can select the next token from a normalized distribution. section 4.4.3

The inference workflow uses softmax to:

  • Normalize each logit to a value from 0 to 1, with all probability values summing to 1. section 4.4.3
  • Reflect temperature effects: lower temperature concentrates probability, while higher temperature spreads it across more tokens. section 4.4.3
  • Pass the resulting distribution to next-token sampling, such as torch.multinomial. section 4.4.3

A temperature-scaled distribution

Applying torch.softmax to logits scaled with temperature 5.0 gives the token " Berlin" the highest probability in the selected vocabulary range, but only 0.0003. At temperature 0.5, its probability rises to 0.3398, while competing probabilities move closer to zero. 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 sampling workflow from rescaled logits through softmax probabilities to next-token selection. section 4.4.3

How Build a Reasoning Model (From Scratch) covers it

How deep it goes
Explains normalization, temperature effects, plotting, and PyTorch usage, then stops before deeper mathematical derivation.
Examples
Uses the " Berlin" token, probability-sum checks, plots, and repeated multinomial sampling.
What it assumes
Assumes logits and temperature scaling, while defining probability normalization through the inference workflow.
What you can do after
Apply it via PyTorch to normalize logits and feed probabilities into token sampling.
How it connects
Connects logits, temperature scaling, probability distributions, and next-token sampling.

Also explained in

Compare how 17 books explain softmax →

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.