Main Point
Decoding controls choose from model scores. Temperature reshapes a score-based distribution, greedy selection takes a highest-ranked available candidate, and top-k or top-p restricts candidates for sampling. Validate the resulting output against the task.
Key Points
- Generation settings can change selections while learned weights remain fixed.
- A common positive-temperature convention uses `softmax(logits/T)`.
- A setting called T=0 requires an implementation convention; do not divide by 0.
- Top-k specifies a retained count; top-p uses cumulative probability under its defined rule.
- Sampling uses a normalized distribution over retained candidates.
- Token probability does not establish whole-answer factual truth or universal reproducibility.
1. Start with vocabulary scores
Use supplied next-token candidates A, B and C with logits (2,1,0). These are classroom inputs, not model-run observations. Unlike L06’s attention calculation, this operation selects an output token rather than mixing source-position value vectors.
2. Rescale with positive temperature
Divide the logits by a positive T before softmax in this worked convention.
| Temperature | Scaled logits | Probabilities, approximately |
|---|---|---|
| T=1 | (2,1,0) | (0.665,0.245,0.090) |
| T=2 | (1,0.5,0) | (0.506,0.307,0.186) |
At T=2, the unrounded probabilities are approximately (0.5064803911,0.3071958857,0.1863237232). They sum to 1; the 3-decimal display sums to 0.999. A remains highest-ranked, while B and C receive larger shares. The weights and context have stayed fixed.
3. Separate greedy selection from sampling
Greedy decoding chooses a highest-scoring available candidate at each step. Here it chooses A at both temperatures. Sampling draws according to the specified distribution, so B or C can be selected too.
A service setting called temperature 0 generally invokes a limiting or greedy convention rather than literal division by 0. Verify the actual generation mode. In the pinned Transformers 4.57.1 implementation example, `do_sample=False` with `num_beams=1` specifies greedy generation; that example does not define every service’s interface or defaults.
4. Restrict a count with top-k
For k=2, retain A and B and remove C. Using the displayed T=1 values, the retained denominator is `0.665+0.245=0.910`. Renormalizing gives approximately (0.731,0.269) for sampling. Full-precision logits yield slightly different unrounded values but the same 3-decimal display.
The probability mass is reassigned within the retained set. This is not the old sampling distribution with a row merely hidden from view.
5. Restrict cumulative mass with top-p
For a separate supplied sorted distribution `(0.50,0.30,0.15,0.05)` and p=0.75, use the smallest leading set whose cumulative mass reaches or exceeds p. The cumulative totals are 0.50 and then 0.80. Retain candidates 1–2 and renormalize by 0.80:
`(0.50/0.80,0.30/0.80)=(0.625,0.375)`.
The retained count can change when the distribution changes. Exact filter order, ties, minimum retained candidates and interactions with temperature depend on the implementation. Do not combine filters by an unrecorded rule and then assume the result matches a particular service.
6. Use a historical study and a pinned implementation carefully
Holtzman and colleagues’ study, initially released 22 April 2019 and revised 14 February 2020, compared generation strategies using the same language model and developed dynamic nucleus sampling. It demonstrates why the selection rule belongs in an experiment record. Its open-ended generation setting does not identify a universal rule for structured records or factual answers.
Transformers 4.57.1 documentation supplies a versioned example of the temperature/top-k/top-p configuration fields. Its publication date is not stated on the cited page; the page was retrieved 30 October 2026 and visibly identifies newer documentation. It is a pinned historical implementation, not a latest-version instruction or a model run.
7. Validate and record the output
If an application allows exactly 1 of 3 category labels, check membership and format, then evaluate classification accuracy. A familiar false continuation can remain highly ranked; lowering temperature does not supply an authoritative source.
Record model/version, context, generation settings and repeated results. Infrastructure revisions or numerical execution can affect repeatability even under nominally deterministic settings. Choose generation controls through the actual task tests rather than assuming a single slider establishes reliability.
8. Closing
You can distinguish fixed learned weights, current scores, candidate filters and selection. Next, ask whether the needed evidence fits in context and can be used reliably within that capacity.
9. Learning Checks
Attempt each question before opening its explanation. Keep supplied givens separate from your calculation.
M14-L11-Q01
For logits (2,1,0), compare T=1 probabilities approximately (0.665,0.245,0.090) with T=2 probabilities approximately (0.506,0.307,0.186). Does the highest-ranked candidate change? Which alternatives become more likely under sampling? Has temperature added factual knowledge?
Your explanation/calculation: ____________________
Show explanation after your attempt
Candidate A remains highest-ranked. B and C become more likely under the stated sampling distributions. The unrounded distributions sum to 1; the displayed T=2 values sum to 0.999 because of rounding. Temperature changed score scaling and selection probabilities without adding a factual source or changing the learned model parameters. Task behavior and factual support require separate evaluation.
M14-L11-P01
A supplied sorted distribution is (0.40,0.25,0.20,0.15). Under the smallest-leading-set rule with top-p=0.70, which candidates remain? Compare top-k=2. Give the normalization denominator for each retained distribution before sampling.
Your explanation/calculation: ____________________
Show explanation after your attempt
The cumulative probabilities are 0.40, 0.65 and 0.85, so top-p=0.70 retains candidates 1–3. Divide their probabilities by 0.85, giving approximately (0.470588,0.294118,0.235294). Top-k=2 retains candidates 1–2; divide by 0.65, giving approximately (0.615385,0.384615). The normalized retained distributions each sum to 1 before sampling. The supplied scores were the same, but the candidate sets differ.
Sources
- Holtzman, Ari, Jan Buys, Li Du, Maxwell Forbes and Yejin Choi. *The Curious Case of Neural Text Degeneration*. Original preprint 22 April 2019; v2, 14 February 2020; ICLR 2020. Primary paper, sections 2.2, 3.1–3.3 and evaluation setup; version history. Retrieved 30 October 2026. Historical open-ended-generation study and nucleus method, not a universal current task ranking.
- Hugging Face. *Transformers 4.57.1: Generation*. Pinned implementation documentation, GenerationConfig fields. Page publication date not stated; retrieved 30 October 2026. Later-version documentation is indicated by the page. This lesson does not execute an API or endorse defaults for a different offering.