Generating Outputs with AI Models
A logit vector is produced by a language model for each input, and each logit corresponds to one token in the vocabulary.
A Tempting Reading of Raw Model Output
When a language model decides what comes next, its first output is a list of numbers, one for each candidate token. A natural 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. This article traces what the model actually produces, why logits must be transformed before they can be read as likelihoods, and how the softmax transformation does that work.
What do you think happens?
A model produces three raw outputs for three candidate tokens: 2.0, 1.0, and -1.0. What kind of numbers are these: probabilities, or something else?
Reveal answer
They are logits, the raw scores a model produces before conversion. They are not probabilities.
Two properties give it away. The value -1.0 is negative, and probabilities must be non-negative. Also, the three numbers sum to 2.0, not to one, so they cannot be a probability distribution. A larger value does indicate a higher probability once the scores are converted, but the raw values themselves are not the probabilities.
What One Forward Pass Produces
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 entire vocabulary, taken at one moment, for one input.
Mapping Positions to Vocabulary Tokens
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. The diagram above uses three illustrative tokens labeled A, B, and C. Position 1 holds the logit for token A, position 2 holds the logit for token B, and position 3 holds the logit for token C. Keeping this correspondence in mind makes the vector easy to interpret, because each number answers one question: how strongly does the model lean toward one particular token?
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 for a set of options 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 transformation is the job of a softmax layer.
Turning Logits into 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 using the formula below. The formula has two parts: the numerator exponentiates the logit at position i, and the denominator adds up the exponentiated values of every logit in the vector.
- 1Start with the logit x_i at position i of the logit vector.
- 2Exponentiate it to get $e^{x_i}$. This value is always positive, which removes the problem of negative logits.
- 3Exponentiate every logit in the vector and add the results together to get the sum in the denominator.
- 4Divide the exponentiated value for token i by that total. Every result is non-negative, and because each value is divided by the same total, the results add up to one.
The exponential step is what makes the output usable as probabilities. Exponentiating turns every logit into a positive number, which removes the problem of negative values. Dividing each result by the sum of all of them forces the outputs to total one. Both properties are exactly what probabilities require.
Worked Example: Converting Three Logits
Softmax on the Logits 2.0, 1.0, and -1.0
A model produces logits 2.0, 1.0, and -1.0 for three candidate tokens A, B, and C. Convert these logits into probabilities using the softmax formula, and check that the results are non-negative and sum to one.
- 1Exponentiate each logit
Compute $e^{2.0} \approx 7.389$, $e^{1.0} \approx 2.718$, and $e^{-1.0} \approx 0.368$. The negative logit -1.0 becomes the positive value 0.368.
- 2Sum the exponentiated values
Add the three results: $7.389 + 2.718 + 0.368 \approx 10.475$. This total is the denominator for every token.
- 3Divide each value by the sum
Token A: $7.389 / 10.475 \approx 0.705$. Token B: $2.718 / 10.475 \approx 0.259$. Token C: $0.368 / 10.475 \approx 0.035$.
- 4Check the two required properties
All three results are non-negative. They sum to $0.705 + 0.259 + 0.035 = 1.000$, so they form a valid probability distribution.
Token A has probability about 0.705, token B about 0.259, and token C about 0.035. The largest logit, 2.0 for token A, produced the largest probability, consistent with the rule that a larger logit corresponds to a higher probability.
Notice what the transformation did not do. It did not change which token ranks highest. Token A had the largest logit and still has the largest probability. What changed is the scale and the form of the numbers. The raw values were negative-capable and summed to 2.0, while the converted values are all positive and sum to one.
Mistakes When Reading Logits
Common mistake Treating the raw logits as probabilities because they look like scores
What it looks likeReading the logit -1.0 as a 100 percent chance of something being false, or as a negative chance.
Why it failsProbabilities must be non-negative, and a logit can be negative. The raw values have not been converted yet.
Do this insteadApply softmax first, then interpret the resulting values as probabilities.
Common mistake Assuming the logits add up to one
What it looks likeAdding 2.0, 1.0, and -1.0 and expecting a total of one.
Why it failsThe logits sum to 2.0 here. Logits are not normalized, so their total has no special meaning.
Do this insteadCheck the total only after exponentiating and dividing, which forces the sum to one.
Common mistake Ignoring the position of each logit
What it looks likeSwapping the scores for token A and token C and then reporting the result as if nothing changed.
Why it failsEach position is tied to one vocabulary token, so swapping values attaches the scores to the wrong tokens.
Do this insteadKeep track of which vocabulary token each position represents before interpreting any value.
Common mistake Skipping the exponential step and dividing the raw logits by their sum directly
Checking a Softmax Result
A model produces logits 0.0, 0.0, and 0.0 for three candidate tokens. Using the softmax formula, what probability does each token receive, and why does the result make sense?
Hints
- Each exponentiated value is e raised to 0.0, which is 1.
- The sum of the three exponentiated values is then 3.
- Divide each value of 1 by that sum, and check that the three results add to one.
Explain in one or two sentences why the logits 2.0, 1.0, and -1.0 cannot be read directly as probabilities, naming both properties that differ.
Hints
- Think about the sign of each value.
- Add the three values and compare the total with one.
Key Takeaways
- A language model produces a logit vector for each input, and each position in that vector corresponds to one token in the model's vocabulary.
- Logits are not probabilities: they can be negative and do not sum to one, while probabilities must be non-negative and sum to one.
- A larger logit corresponds to a higher probability, but the raw scores must be converted before they can be read as probabilities.
- The softmax formula exponentiates each logit and divides it by the sum of all exponentiated logits, producing non-negative values that sum to one.