Logits and Softmax Transformation
A logit vector is produced by a language model for each input, and each logit corresponds to one token in the vocabulary.
Try it: Text Vectorization: Tokens to Vectors
The text-to-tensor pipeline: standardize, split into tokens, build a frequency-ranked vocabulary with padding and [UNK], map tokens to integer ids, pad or truncate, then one-hot or multi-hot encode and look the ids up in an embedding table.
How it works
- Standardize: lowercase and delete punctuation.
- Split on whitespace into tokens.
- Build the vocabulary: 0 = padding, 1 = [UNK], then words by frequency (ties: first appearance), capped at max tokens.
- Map each token to its id (1 if it did not make the vocabulary), then pad with 0 or truncate to the sequence length.
- Encode: one-hot rows per position or one multi-hot row per text; embed: id k selects row k of the embedding table.
Default run (18 steps): Raw text (59 characters): "The movie was great. The plot was great, the acting wasn't!". A model cannot read strings, so it is turned into numbers step by step. … Embedding lookup: id k selects row k of a fixed 8 x 3 table, giving a (8, 3) dense matrix instead of (8, 8) sparse one-hots. Row 0 (padding) is looked up too; a trained Embedding layer would learn these rows.
Simplified: Bounded ASCII text (up to 200 characters, 40 tokens), whitespace splitting only, and a small FIXED embedding table (a real Embedding layer learns its rows). The multi-hot vector keeps the padding slot (always 0) so its positions line up with the ids.
Loading the simulation…
Reading a Model's Raw Output
When a language model is asked what should come next, its first output is a list of numbers. A common first reaction is to read each number as the chance that a particular token comes next. The numbers look like scores that rank the options, and a larger number seems to mean a more likely token. Part of that intuition is correct. The belief that the raw numbers already are probabilities, however, is a misconception. The raw numbers are called logits, and they are a different kind of quantity.
What do you think happens?
A model produces three numbers for three candidate tokens: 2.0, 1.0, and -1.0. What kind of numbers are these? Are they probabilities?
Reveal answer
They are logits, raw scores that are not yet probabilities.
They rank the tokens, since a larger number signals a stronger lean toward that token. But one value is negative, and the three values do not add up to one. Probabilities must be non-negative and must sum to one, so these raw values cannot be read directly as probabilities.
Mapping Each Position to a Token
For each input the model processes, it produces a logit vector. This is simply an ordered list of numbers. Every position in that list corresponds to one token in the model's vocabulary. If the vocabulary has N tokens, the logit vector has N entries, and each entry is the model's raw score for the token at that same position. The vector is therefore a complete snapshot of the model's current leaning across the whole vocabulary, taken at one moment for one input.
Because the position of each number is tied to a specific token, the order of the list matters. Reading logit number 2 means reading the score for vocabulary token 2, not some generic value. Keeping that correspondence in mind makes the vector easy to interpret, because each number answers the question of how strongly the model leans toward one particular token. Shuffling the numbers without shuffling the tokens would attach every score to the wrong word.
Why Logits Are Not Probabilities
Logits share one feature with probabilities. A larger logit corresponds to a higher probability once the scores are converted. The resemblance ends there, because logits differ from probabilities in two specific ways. First, logits can be negative, while probabilities must be non-negative. Second, logits do not sum to one, while the probabilities across the vocabulary must total one. These two differences explain why the raw output must be transformed before it can be read as a distribution of likelihoods. The job of that transformation is performed by a softmax layer.
| Property | Logits | Probabilities |
|---|---|---|
| Can the value be negative? | Yes | No, must be non-negative |
| Do the values sum to one? | Not required, and usually not true | Yes, they must total one |
| Does a larger value mean a higher likelihood? | Yes, in ranking terms | Yes, and the values give the likelihood directly |
| Can it be read directly as a chance? | No, it must be transformed first | Yes |
Logits and probabilities compare on the same ranking idea but differ in allowed values and total
From Logits to Probabilities with Softmax
To convert logits to probabilities, a softmax layer is often used. Suppose the model has a vocabulary of N tokens and the logit vector is the list of values x_1 through x_N. The probability for token i, written as p_i, is computed from the logit at position i. The softmax step has two parts. It first exponentiates every logit, and then it divides each exponentiated value by the sum of all the exponentiated values.
Each part of the formula solves one of the two problems from the previous section. The exponential step turns every logit into a positive number, so a negative logit no longer produces a negative result. Dividing each result by the total of all of them forces the outputs to sum to one. Both properties are exactly what probabilities require. The formula reads the same way for every token, so the same two operations apply to the whole vocabulary.
Working Through the Three-Token Case
Softmax on logits 2.0, 1.0, and -1.0
Convert the logit vector 2.0, 1.0, -1.0 into probabilities for three tokens. Check that the results are non-negative and sum to one.
- 1Exponentiate each logit
Compute e raised to each logit. The value for 2.0 is about 7.389, the value for 1.0 is about 2.718, and the value for -1.0 is about 0.368. Notice that the negative logit has become a positive number.
- 2Sum the exponentiated values
Add the three results: 7.389 plus 2.718 plus 0.368 gives about 10.475. This total is the normalizing denominator for every token.
- 3Divide each value by the sum
For the first token, 7.389 divided by 10.475 is about 0.705. For the second token, 2.718 divided by 10.475 is about 0.259. For the third token, 0.368 divided by 10.475 is about 0.035.
- 4Check the two required properties
All three results are non-negative. They add to about 0.999, and the small gap from exactly one comes from rounding each value to three decimal places.
The probabilities are about 0.705, 0.259, and 0.035. The token with the largest logit, 2.0, receives the largest probability.
Read the diagram as a change in the values, not in the tokens. Each token keeps its position and its identity. The negative score of -1.0 becomes a small positive probability, and the three values now total one. The ranking survives the transformation, because 2.0 was the largest logit and 0.705 is the largest probability.
Common Misreadings of Logits
The following errors come up often when learners first meet raw model output. Each one follows from treating logits as if they were already probabilities.
Common mistake Reading a logit directly as the chance of a token
What it looks likeSeeing a logit of 2.0 and concluding the token has a 200 percent chance.
Why it failsLogits are raw scores and are not yet probabilities, so they do not express a chance on their own.
Do this insteadApply softmax to the whole logit vector first, then read the resulting probability for that position.
Common mistake Assuming a negative logit means impossible
What it looks likeDismissing the token with logit -1.0 as having zero chance.
Why it failsA negative logit is still a valid raw score. The exponential step in softmax turns it into a positive number.
Do this insteadKeep the token in the calculation and let softmax determine its share of the total.
Common mistake Expecting logits to add up to one
What it looks likeChecking 2.0 plus 1.0 plus -1.0 and expecting a total of one.
Why it failsThe source states that logits do not sum to one. Only probabilities are required to sum to one.
Do this insteadCheck the sum only after the softmax division has produced the probabilities.
Common mistake Losing the position-to-token correspondence
What it looks likeSorting the logit vector by size and then reading the result as if the tokens were still in their original order.
Why it failsEach position is tied to one specific vocabulary token, so reordering the numbers attaches the scores to the wrong tokens.
Do this insteadKeep track of which position belongs to which token, or sort the tokens along with their scores.
Trying a Second Logit Vector
A model's vocabulary has three tokens, and the logit vector is 1.0, 0.0, -1.0. Apply the softmax steps to find the three probabilities. Then state which token receives the highest probability and confirm that your three values are non-negative and sum to one.
Hints
- Start by computing e raised to 1.0, e raised to 0.0, and e raised to -1.0 separately.
- The value for 0.0 is the same as e raised to zero, which equals one.
- Add the three exponentiated values to get the single total you will divide by.
- The highest probability should belong to the position that had the highest logit.
Pulling the Steps Together
Across the example, the logit vector kept its meaning at every stage. Each position stayed tied to one vocabulary token, the raw values were allowed to be negative and to total any amount, and softmax then converted them into a valid distribution. Only after that final conversion can the numbers be read as the model's probabilities for each token.
Key Takeaways
- A logit vector is the raw ordered output a language model produces for one input, with one entry for each token in the vocabulary.
- Logits are not probabilities: a larger logit ranks higher, but logits can be negative and do not sum to one.
- The softmax layer converts logits to probabilities by exponentiating each logit and dividing by the sum of all exponentiated logits.
- The exponential step makes every value positive and the division forces the total to one, which are the two properties probabilities require.