Exercises — Logits
Self-check questions, exercises, and worked answers
Check your understanding
- If the vocabulary contains \(V\) tokens, how many components does the logit vector contain at one position?
Show answer
It contains \(V\) components, one for each vocabulary token.
- Why does a logit with value 8 not mean an 80% probability?
Show answer
A logit is an unnormalized real-valued score. It is neither bounded between 0 and 1 nor constrained to sum to one. A separate transformation is needed to obtain a probability distribution.
- What does the argmax of a logit vector identify?
Show answer
It identifies the token with the highest score in that vector. By itself, it does not measure confidence or truth.
- Compare \(z=(2,1)\) and \(z'=(102,101)\). The logits are much larger in the second vector. Is the softmax distribution different? Why?
Show answer
No. The second vector is obtained by adding the same constant (100) to every component. This offset cancels in the softmax formula, so both vectors produce the same distribution. The absolute level of logits therefore has no standalone meaning; their differences matter.
From final states to the next-token distribution
A toy causal GPT receives the unpadded prefix \((A,B)\). The final states entering the output head are \(h_1=(\ln 2,0)\) and \(h_2=(0,\ln 3)\). The vocabulary is \((A,B,C)\) and the output head has weight rows \(w_A=(1,0)\), \(w_B=(0,1)\), and \(w_C=(0,0)\), with zero bias. At position \(t\), candidate \(i\) gets the score \(h_t\cdot w_i\).
- Compute the logits for both positions and give the shape of the resulting matrix.
- Apply softmax to each row. Which axis is normalized, and what must the probabilities sum to at each position?
- Which prefix conditions each distribution? Which distribution is used to predict the token after the full prefix \((A,B)\)?
Show the worked answer
- The logit matrix has shape \((2,3)\). Its rows are positions and its columns are vocabulary candidates. The rows are \((\ln 2,0,0)\) and \((0,\ln 3,0)\).
- Softmax normalizes the vocabulary axis independently at each position. The resulting distributions are \((1/2,1/4,1/4)\) and \((1/5,3/5,1/5)\), each summing to \(1\).
- The first row gives \(P(\cdot\mid A)\). It assigns probability \(1/4\) to the observed token \(B\). The second gives \(P(\cdot\mid A,B)\). Decoding uses this distribution to extend the full prefix.
Return to the review plan · Understand Transformer computation · From hidden states to the predictive distribution
Two softmax operations, two axes
A toy GPT has vocabulary \((A,B,C)\) and receives prefix \((A,B,A)\). For the query at the last position in a causal attention head, the already-scaled scores are \((\ln 2,0,0)\) in position order. All three keys are accessible. After the blocks and the output head, the logits at the same position are \((0,\ln 2,0)\) in vocabulary order.
- Compute softmax over the attention scores. What does each component represent, and what is it used for?
- Compute softmax over the vocabulary logits. What probability does it assign to \(A\) as the next token?
- Add the weights of the two positions containing \(A\). What does the total measure?
Show the reasoning
| Computation | Normalized axis | Result |
|---|---|---|
| Attention softmax | Key positions \(1,2,3\) | \((1/2,1/4,1/4)\), the coefficients that weight the three value vectors. |
| Output softmax | Vocabulary tokens \(A,B,C\) | \((1/4,1/2,1/4)\), the probabilities of the three possible next tokens. |
Together the two positions containing \(A\) receive \(3/4\) of the weight in this attention row. That total describes how much weight is assigned to those positions in the weighted sum, where each has its own value vector. The distribution predicted by the output softmax assigns \(1/4\) to \(A\).
To trace the role of masking and shifted targets, return to the second position in the three-sequence exercise.
Return to the review plan · Understand Transformer computation · From hidden states to the predictive distribution