Foundations

Probability you actually need

Conditional probability, softmax over 248,320 outcomes, log probabilities, and what temperature 1.0 versus 0.7 actually does to Qwen3.8-27B.

Updated

01 · Concept

Concept

Here is a concrete situation before any vocabulary. You have run Qwen3.8-27B on a prompt and the final layer has handed you 248,320 raw numbers, one per output-tensor row. They are not probabilities: some are negative, some are large, and they certainly do not sum to anything convenient. Somebody now has to turn that pile into an actual distribution, and then somebody has to choose a token from it. Almost all of the probability you need for this course is the machinery for those two steps.

Start with what a distribution is. A probability is a number between zero and one expressing uncertainty under a model. For mutually exclusive possibilities the probabilities add to one. After any runtime masking, softmax produces a categorical distribution: non-negative values summing to one over the candidates the decoder may select. Qwen’s raw output vector has length 248,320, while its tokenizer artifacts map 248,077 ids. Notice what this makes explicit. The distribution is the model’s answer. Picking a token from it is a separate decision made by code you configure, not by the network.

Probability is always conditioned on something. We write P(A)P(A) for the probability of AA, and P(AB)P(A \mid B) for the probability of AA given that BB holds. Language modelling is conditional through and through: P(xtx1,,xt1)P(x_t \mid x_1,\ldots,x_{t-1}). The token Mercury is a fine continuation of the closest planet to the Sun is and a poor one after the liquid metal is. Conditioning is the whole game, and the history in lesson 0.2 is the history of how much of x1,,xt1x_1,\ldots,x_{t-1} a model could afford to look at.

The chain rule assembles a sequence probability from those conditionals:

P(x1,,xT)=t=1TP(xtx1,,xt1).P(x_1,\ldots,x_T)=\prod_{t=1}^{T}P(x_t\mid x_1,\ldots,x_{t-1}).

This identity is why repeated next-token prediction defines a probability for a whole passage. It also explains an immediate practical problem: multiply a few hundred numbers below one and the result underflows to zero in floating point. So implementations work in logarithms. Because log(ab)=loga+logb\log(ab) = \log a + \log b, the product becomes a sum. The log of a probability is at most zero, closer to zero for likelier events, tending to minus infinity for impossible ones. Training minimizes negative log-likelihood, which flips the sign so that better predictions give a smaller number, and averaging over tokens makes sequences of different length comparable.

Now the bridge from raw scores to that distribution. Given logits ziz_i, softmax computes

pi=ezijezj.p_i=\frac{e^{z_i}}{\sum_j e^{z_j}}.

Exponentiating makes every value positive; dividing by the total makes them sum to one. One property is worth memorizing: adding the same constant to every logit leaves the probabilities unchanged, because the constant factors out of numerator and denominator. Softmax cares only about differences between logits.

Work the temperature example numerically, using three logits and ignoring the other 248,317 for legibility. Take z=(4.0,2.0,1.0)z = (4.0, 2.0, 1.0). Exponentiating gives 54.6054.60, 7.397.39, and 2.722.72, summing to 64.7164.71, so the probabilities are about 0.8440.844, 0.1140.114, and 0.0420.042. That is temperature 1.0, the preset Qwen3.8-27B uses in its thinking mode. Now apply temperature T=0.7T = 0.7, the model’s instruct-mode preset. Temperature divides the logits before softmax: z/T=(5.714,2.857,1.429)z/T = (5.714, 2.857, 1.429). Exponentiating gives roughly 303.1303.1, 17.417.4, and 4.174.17, summing to 324.7324.7, so the probabilities become about 0.9340.934, 0.0540.054, and 0.0130.013. The leader gained nine points of probability and the tail lost most of what it had. Nothing about the model changed; only the sharpness of the reading.

There is a classic wrong turn here that is worth walking into deliberately. Suppose you had instead divided the probabilities by 0.7 and renormalized. You would get 0.844/0.7=1.2060.844/0.7 = 1.206, 0.1630.163, and 0.0600.060, summing to 1.4291.429; dividing through by that total returns 0.8440.844, 0.1140.114, 0.0420.042. Exactly the original distribution. Scaling every probability by a constant and renormalizing is a no-op, because the constant cancels in the same way an added constant cancels for logits. Temperature only does anything because it acts before the exponential, where a multiplicative change to the exponent becomes a nonlinear change to the result. If your sampler applies temperature to the wrong side of the softmax, the parameter will appear to do nothing at all, and this is a real bug people ship.

Two rules prevent most probabilistic reasoning errors. First, P(AB)P(A \mid B) is not P(BA)P(B \mid A); a symptom can be common among patients with a rare disease while the disease stays rare among people with the symptom. Second, expectation is not an outcome: the expected value E[X]=xp(x)xE[X] = \sum_x p(x) x of a fair die is 3.5, and no face shows 3.5. Expected loss, the quantity training minimizes, is an average over examples that no single example need resemble.

The working toolkit is small: normalize with softmax, condition on context, multiply conditionals with the chain rule, work in logs for stability, and keep the model’s distribution firmly distinct from the world it describes. With those five pieces, cross-entropy, entropy, perplexity, and every sampling method in track 7 are variations rather than new subjects.

02 · Analogy

Analogy

Picture a weather desk with a hundred chips spread across tomorrow: sixty on rain, thirty on cloud, ten on sun. New radar does not declare a future; it slides chips around the table. The forecast is the whole arrangement, not the label under the tallest pile. Temperature is a croupier who, before anyone reads the table, either rakes chips toward the tallest pile or spreads them outward. The croupier adds no information about tomorrow. It only changes how decisive the table looks.

03 · Teach it back

Teach it back

Explain conditional probability and log probability with a next-token example, then say precisely what temperature does and where in the pipeline it acts.

Minimum: 80 characters and 15 words. Your writing stays only in this browser.

Waiting for your explanation.

Compare with a model answer

A language model estimates P(next token | tokens so far); the same token can be likely after one prefix and negligible after another. A whole sequence probability is the product of those conditionals, which underflows quickly, so implementations sum log probabilities instead. Softmax turns raw scores into that distribution by exponentiating and normalizing. Temperature divides the logits before softmax, not the probabilities after it: dividing probabilities by a constant and renormalizing changes nothing, because the constant cancels. Lower temperature sharpens the distribution toward the top-scoring token, higher temperature flattens it, and neither supplies new evidence about which token is correct.

04 · Check your understanding

Check your understanding

01Given logits 4.0, 2.0 and 1.0, applying softmax at temperature 0.7 instead of 1.0 raises the top probability from about 0.84 to about 0.93. Why?
Answer and explanation

Dividing logits by 0.7 enlarges the gaps between them before exponentiation — Temperature rescales the differences between logits; softmax then exponentiates the enlarged gaps, concentrating mass on the leader. The logits themselves never change.

02What must be true after softmax normalizes Qwen3.8-27B's next-token logits?
Answer and explanation

All 248,320 values are non-negative and sum to one — Softmax exponentiates every logit, making it positive, then divides by the total, so the result is a valid categorical distribution regardless of the sign of the logits.

03A trigram context appeared in training, but one particular continuation never followed it. Why is that continuation's zero probability especially destructive?
Answer and explanation

Sequence probability is a product of conditionals, so one zero factor makes the whole sequence impossible — For a seen context the denominator is nonzero, so an unseen continuation receives probability zero. The chain rule multiplies conditionals; that factor sends the sequence probability to zero and its logarithm to negative infinity.

Complete the teach-back and answer the quiz correctly to finish this lesson.

◎ · Evidence marker

Sources

  1. Claude E. Shannon (1948). A Mathematical Theory of Communication.
  2. Qwen Team (2026). Qwen3.8-27B Model Card.