Softmax and how LLM is predicting the next word

When a large language model (LLM) predicts the next word, it doesn’t pick a word straight away. It first gives a score to every word in its vocabulary. Softmax then turns those scores into probabilities, and the model uses the probabilities to choose the next word.
Step 1: The model gives every word a score
Take this sentence: I like to drink ____. The model’s final layer produces a raw score for each possible next word:
| Word | Score (logit) |
|---|---|
| tea | 5.2 |
| coffee | 4.8 |
| water | 3.1 |
| car | -1.5 |
These raw scores are called logits. They are not probabilities: they can be negative, and they don’t add up to 1. To see where they come from, read how logits are formed in an LLM.
Step 2: Softmax turns scores into probabilities
Softmax is a function that converts a list of scores into probabilities. For each word i:
P(word i) = e^(score i) / sum of e^(score j) for every word j
It does two things:
- It makes every value positive. The exponential ex is always above 0, even for a negative score like -1.5.
- It makes the values add up to 1. Dividing by the total turns each value into a share of the whole.
Worked example
Here is the full calculation for our four words (rounded):
| Word | Score | escore | Probability |
|---|---|---|---|
| tea | 5.2 | 181.27 | 181.27 / 325.20 = 0.557 |
| coffee | 4.8 | 121.51 | 121.51 / 325.20 = 0.374 |
| water | 3.1 | 22.20 | 22.20 / 325.20 = 0.068 |
| car | -1.5 | 0.22 | 0.22 / 325.20 = 0.001 |
| Total | 325.20 | 1.000 |
So the model thinks tea is the most likely next word (about 56%), coffee is close behind (37%), and car is almost impossible.
Notice that a gap of only 0.4 in score (5.2 vs 4.8) becomes a large gap in probability. Softmax exaggerates differences, which helps the model commit to a choice.

Step 3: The model picks the next word
Once it has probabilities, the model chooses a word. There are a few common ways:
- Greedy: always pick the most likely word (tea).
- Sampling: pick at random, weighted by the probabilities, so coffee wins about 37% of the time.
- Temperature: divide the scores by a number before softmax to make choices safer or more creative. Try it in the LLM temperature simulator.
- Top-k and top-p: only sample from the most likely words, so very unlikely words such as car are never chosen.
Summary
The model scores every word, softmax turns those scores into probabilities that add up to 1, and a sampling rule picks the next word. The model repeats this for every single word it writes.
3 Responses