Temperature Scaling, Top-k & Nucleus (Top-p) Sampling
How do temperature scaling, top-k filtering, and nucleus (top-p) sampling mathematically reshape probability distributions to eliminate repetitive loops and hallucinated tail tokens?
How this lesson unfolds.
Begin with How do thermodynamic temperature scaling and cumulative probability thresholds balance creative diversity with factual stability?. Follow the visual diagrams to build an intuitive, mathematically grounded mental model of temperature scaling, top-k & nucleus sampling.
How does temperature scaling physics sampling operate mathematically within the overall Temperature Scaling, Top-K & Nucleus Sampling?
Imagine heating up water molecules in a pot. At near absolute zero (Temperature -> 0), the water freezes solid into ice (pure deterministic greedy choice). As you turn up the burner (Temperature = 1.0), molecules move freely with creative fluidity. Turn the stove to 5.0, and the water boils violently into chaotic vapor.
- $$\mathbf{y} = f(\mathbf{X} \mathbf{W} + \mathbf{b})$$
- Learning goalFormulate Boltzmann temperature scaling and evaluate how temperature modulates entropy and token diversity.
- Helpful foundationsMatrix multiplication and tensor broadcasting · Language Models are Unsupervised Multitask Learners (Radford et al., OpenAI 2019) · Attention Is All You Need (Vaswani et al., 2017)
- Common trapSetting temperature = 0.0 directly in software; dividing by zero causes NaN errors. Implement T=0 as greedy argmax or set T = 1e-5.
- Next connectionExplore the physical thermodynamic roots in Bridge Temperature Scaling Physics.
More context & mechanics
Temperature scaling divides unnormalized logits by scalar T > 0 before computing softmax:
P(wᵢ) = (exp(zᵢ / T)) / (∑ⱼ exp(zⱼ / T))
- As T → 0, P(w_(max)) → 1.0 (recovering greedy argmax).
- At T = 1.0, standard model probabilities are preserved unchanged.
- As T → ∞, P(wᵢ) → 1/V (converging to a uniform distribution).
Used in all conversational LLM APIs (OpenAI, Anthropic, Google Gemini). Default temperature is typically 0.7 for conversational chat, 0.2 for coding and reasoning, and 1.0 for creative brainstorming.
Borrowed directly from statistical thermodynamics, specifically Ludwig Boltzmann's 1877 Boltzmann distribution Pᵢ ∝ e^(−Eᵢ / k_B T) relating particle states to thermal temperature.
Temperature does not change logit ranking; it only changes the sharpness of the probability peaks.
How does bridge temperature scaling physics operate mathematically within the overall Temperature Scaling, Top-K & Nucleus Sampling?
In physics, high temperature gives low-energy particles enough kinetic energy to jump out of deep potential wells. In language models, high temperature gives low-probability words enough probability to jump out from behind the obvious dominant word.
- $$\mathbf{y} = f(\mathbf{X} \mathbf{W} + \mathbf{b})$$
- Learning goalProve that relative probability ratios scale exponentially with inverse temperature 1/T.
- Helpful foundationsMatrix multiplication and tensor broadcasting · Language Models are Unsupervised Multitask Learners (Radford et al., OpenAI 2019) · Attention Is All You Need (Vaswani et al., 2017)
- Common trapThinking temperature changes the order of tokens; the rank order of logits is strictly invariant under positive temperature scaling.
- Next connectionLearn to clip the hazardous long tail of tokens in Top-k Truncation Filtering Probability Tail.
More context & mechanics
The relative probability ratio between two candidate tokens i and j is given by:
(P(wᵢ)) / (P(wⱼ)) = exp((zᵢ - zⱼ) / (T))
When T = 0.5, a logit difference of 2.0 becomes an effective gap of 4.0 (e⁴ ≈ 54.6× preference). When T = 2.0, that same gap shrinks to 1.0 (e¹ ≈ 2.7× preference).
Foundational in simulated annealing algorithms, diffusion model score scaling, and temperature-scheduled fine-tuning regimes.
Formulated by Kirkpatrick, Gelatt, and Vecchi (1983) in 'Optimization by Simulated Annealing', linking statistical mechanics to discrete optimization.
Higher temperatures flatten energy landscapes; lower temperatures freeze parameters into the deepest local minimum.
How does top k truncation filtering probability tail operate mathematically within the overall Temperature Scaling, Top-K & Nucleus Sampling?
Imagine a casting director choosing actors for a role. Instead of considering all 50,000 applicants (including toddlers and pets), the director immediately discards everyone except the top 40 best candidates, and samples among those 40.
- $$\mathbf{y} = f(\mathbf{X} \mathbf{W} + \mathbf{b})$$
- Learning goalImplement top-k logit filtering using torch.topk and demonstrate that excluded tokens have zero probability post-softmax.
- Helpful foundationsMatrix multiplication and tensor broadcasting · Language Models are Unsupervised Multitask Learners (Radford et al., OpenAI 2019) · Attention Is All You Need (Vaswani et al., 2017)
- Common trapUsing a fixed top-k on flat or peaked distributions; if 100 words are equally valid, top-40 cuts off good options; if only 1 word is valid, top-40 forces 39 bad options into the pool.
- Next connectionSolve the fixed-cutoff problem dynamically in Nucleus Top-p Sampling Cumulative Probability Threshold.
More context & mechanics
Top-k filtering sorts logits in descending order, identifies the k-th highest value z^((k)), and sets all logits strictly below this threshold to -∞:
z'ᵢ = zᵢ & if zᵢ ≥ z^((k)) \ -∞ & otherwise
When softmax is computed over z', values with -∞ evaluate to e^(−∞) = 0, completely eliminating the bottom V - k tokens.
Standard setting in open-source inference engines (e.g. `topₖ = 40` or `topₖ = 50`), ensuring zero probability is allocated to gibberish tokens.
Popularized by Fan, Lewis, and Dauphin (2018) in 'Hierarchical Neural Story Generation', dramatically reducing story degradation.
Cut the tail with top-k to banish bizarre, catastrophic hallucinations.
How does nucleus top p sampling cumulative probability threshold operate mathematically within the overall Temperature Scaling, Top-K & Nucleus Sampling?
Instead of always picking a rigid count like 40 people, an elevator captain looks at weight: 'I will keep letting people in until the total weight reaches 90% of capacity, then close the door.' If a sumo wrestler enters (high-probability word), the door closes immediately. If children enter, many can fit.
- $$\mathbf{y} = f(\mathbf{X} \mathbf{W} + \mathbf{b})$$
- Learning goalImplement cumulative nucleus filtering using torch.cumsum and analyze dynamic candidate set contraction.
- Helpful foundationsMatrix multiplication and tensor broadcasting · Language Models are Unsupervised Multitask Learners (Radford et al., OpenAI 2019) · Attention Is All You Need (Vaswani et al., 2017)
- Common trapFiltering top-p directly on unnormalized logits; cumulative sums must be calculated on sorted softmax probabilities, then applied as a mask back onto logits.
- Next connectionUnify temperature, top-k, and top-p into a production engine in Unified Autoregressive Generation Pipeline.
More context & mechanics
Nucleus (top-p) sampling sorts probabilities in descending order p_((1)) ≥ p_((2)) ≥ ṡ ≥ p_((V)) and finds the minimal subset whose cumulative mass exceeds threshold p ∈ (0, 1):
∑_(i=1)^(k^*) p_((i)) ≥ p
All tokens with rank index > k^ have their logits set to -∞. The set size k^ expands dynamically when the model is uncertain, and contracts to 1 when confident.
The gold-standard decoding strategy used across modern AI models (ChatGPT, Claude, LLaMA-3), typically configured with `top_p = 0.9` or `0.95`.
Introduced by Ari Holtzman et al. (2019) in 'The Curious Case of Neural Text Degeneration', demonstrating that human text does not follow fixed-k distributions.
Top-p expands when uncertain and contracts when sure: dynamic probability mass keeps sampling natural.
How does unified autoregressive generation pipeline operate mathematically within the overall Temperature Scaling, Top-K & Nucleus Sampling?
The complete, polished gearbox of modern text generation: raw logits enter, temperature scales the steepness, top-k trims the distant tail, top-p trims the cumulative fringe, softmax samples the winner, and repetition penalties keep the voice fresh.
- $$\mathbf{y} = f(\mathbf{X} \mathbf{W} + \mathbf{b})$$
- Learning goalBuild a modular, production-ready text generation function combining temperature, top-k, top-p, and repetition penalties.
- Helpful foundationsMatrix multiplication and tensor broadcasting · Language Models are Unsupervised Multitask Learners (Radford et al., OpenAI 2019) · Attention Is All You Need (Vaswani et al., 2017)
- Common trapApplying top-k after top-p; top-k must be applied first as a fast broad filter, followed by fine dynamic top-p thresholding.
- Next connectionProceed to Chapter 30 to learn how to save, serialize, and load trained model checkpoints securely.
More context & mechanics
The complete generation sampling pipeline applies transformations in strict order:
- Repetition penalty: zᵢ arrow zᵢ / θ for tokens already in context
- Temperature scaling: z arrow z / T
- Top-k truncation: mask tokens beyond rank k
- Top-p nucleus masking: mask tokens beyond cumulative mass p
- Categorical sampling: w_(next) ~ Categorical(softmax(z))
- Append and repeat until `<eos>` or max length.
Core decoding algorithm embedded in production inference servers such as vLLM, HuggingFace TGI, and llama.cpp.
Synthesized through years of open-source community experimentation, merging thermodynamic scaling, statistical filtering, and penalty heuristics.
Penalty → Temperature → Top-k → Top-p → Softmax → Sample.
How does temperature scaling simulate physical thermodynamic phase transitions between crystalline order and gas chaos?
Imagine water in a flask. At freezing temperatures (0^∘C, T = 0.05), water molecules lock into a rigid, perfectly ordered ice crystal: there is zero freedom to move, and the lowest energy state is locked in (argmax deterministic generation). At room temperature (20^∘C, T = 0.7), it is a fluid liquid that flows gracefully while maintaining coherence. At boiling heat (100^∘C, T = 3.0), water turns into frantic steam gas: molecules fly randomly in all directions, crashing chaotically into walls (pure random gibberish).
- $$Scale logits by inverse temperature beta = 1/T, proving that T -> 0 freezes into zero-entropy crystalline ground states while T -> inf boils into high-entropy gas states.$$
- Learning goalDerive the thermodynamic limits of the softmax distribution as T -> 0 and T -> infinity.
- Helpful foundationsBoltzmann distribution · Limits of exponential functions · A Learning Algorithm for Boltzmann Machines (Ackley, Hinton, Sejnowski, 1985)
- Common trapSetting T = 0.0 in software directly; evaluating z / 0 produces division-by-zero crashes, so production engines implement T = 0 by switching to an explicit `torch.argmax()` kernel.
- Next connectionLet's trace this temperature math step-by-step with small toy numbers to see exactly how the decimal probabilities change.
More context & mechanics
In statistical physics, the probability of a particle occupying state with energy Eᵢ at temperature T is governed by the Boltzmann distribution:
Pᵢ = (e^(−Eᵢ / (k_B T))) / (Z)
In language models, logits act as negative energy levels (zᵢ = -Eᵢ / k_B):
qᵢ(T) = (e^(zᵢ / T)) / (∑ⱼ e^(zⱼ / T))
We analyze the thermodynamic limits:
- Freezing Regime (T → 0, Absolute Zero):
lim_(T → 0) qᵢ(T) = 1/M & if zᵢ = maxⱼ zⱼ (M-fold degenerate ground state) \ 0 & if zᵢ < maxⱼ zⱼ
Entropy collapses to H → 0. The model selects the argmax token deterministically.
- Boiling Regime (T → ∞, Infinite Thermal Energy):
lim_(T → ∞) zᵢ/T = 0 ⟹ e^(zᵢ / T) → 1 ⟹ qᵢ(T) = 1/K
Entropy reaches maximum H → log K. Every word in the 50,000-token dictionary becomes equally likely, producing unreadable noise.
LLM serving runtimes (Ollama, vLLM, HuggingFace) expose temperature `T` directly to users: T = 0.0 for SQL query generation, T = 0.7 for assistant chat, T = 1.2 for creative poetry.
Ludwig Boltzmann established statistical thermodynamics in 1877. Geoffrey Hinton applied simulated annealing and temperature to Boltzmann Machines in 1985.
- Cold (T -> 0) freezes into ice (argmax).
- Hot (T -> inf) boils into steam (uniform noise).
How do probability distributions shift across T = 0.5, T = 1.0, and T = 2.0 on a concrete three-logit toy example?
Let's put aside abstract formulas and do elementary arithmetic. Suppose your model outputs three candidate words: 'dog' (logit 2.0), 'cat' (logit 1.0), and 'fish' (logit 0.0). At normal temperature (T = 1), 'dog' gets 66% of the probability pie, 'cat' gets 24%, and 'fish' gets 9%. If you cool it down to T = 0.5, 'dog' surges to a crushing 84% monopoly. If you heat it up to T = 2.0, 'dog' drops to 47%, while 'fish' climbs from 9% to 17%. Watching the numbers move demystifies temperature completely.
- Learning goalCalculate exact multi-decimal probability vectors across cold, neutral, and hot temperature scaling factors.
- Helpful foundationsHigh-school exponential calculations · Softmax formula · Statistical Mechanics of Learning (Watkin, Rau, Biehl, 1993)
- Common trapBelieving temperature changes the rank order of tokens; the argmax token at T=0.5, T=1.0, and T=2.0 is ALWAYS token A, as scaling by positive T strictly preserves order.
- Next connectionEven with temperature tuned, wild outliers in the long tail can ruin generation. How do we truncate the tail? We compare Top-K vs Nucleus (Top-p) sampling.
More context & mechanics
Consider logits z = [2.0, 1.0, 0.0] for classes [A, B, C].
1. Neutral Temperature (T = 1.0):
- Scaled logits: z / 1.0 = [2.0, 1.0, 0.0]
- Exponentials: e^(2.0) ≈ 7.3891, e^(1.0) ≈ 2.7183, e^(0.0) = 1.0000
- Partition sum: Z = 7.3891 + 2.7183 + 1.0000 = 11.1074
- Probabilities:
- P(A) = 7.3891 / 11.1074 = 0.6652 (66.5\%)
- P(B) = 2.7183 / 11.1074 = 0.2447 (24.5\%)
- P(C) = 1.0000 / 11.1074 = 0.0900 (9.0\%)
2. Cold Temperature (T = 0.5 — Freezing):
- Scaled logits: z / 0.5 = [4.0, 2.0, 0.0]
- Exponentials: e^(4.0) ≈ 54.5982, e^(2.0) ≈ 7.3891, e^(0.0) = 1.0000
- Partition sum: Z = 54.5982 + 7.3891 + 1.0000 = 62.9873
- Probabilities:
- P(A) = 54.5982 / 62.9873 = 0.8668 (86.7\% — dominant peak!)
- P(B) = 7.3891 / 62.9873 = 0.1173 (11.7\%)
- P(C) = 1.0000 / 62.9873 = 0.0159 (1.6\% — crushed!)
3. Hot Temperature (T = 2.0 — Boiling):
- Scaled logits: z / 2.0 = [1.0, 0.5, 0.0]
- Exponentials: e^(1.0) ≈ 2.7183, e^(0.5) ≈ 1.6487, e^(0.0) = 1.0000
- Partition sum: Z = 2.7183 + 1.6487 + 1.0000 = 5.3670
- Probabilities:
- P(A) = 2.7183 / 5.3670 = 0.5065 (50.7\%)
- P(B) = 1.6487 / 5.3670 = 0.3072 (30.7\%)
- P(C) = 1.0000 / 5.3670 = 0.1863 (18.6\% — flattened toward uniform!)
This exact arithmetic trace is calculated for every token across 50,000 vocabulary logits on GPU hardware during model inference.
This four-decimal worked example serves as the canonical diagnostic check used in unit testing LLM sampling pipelines in PyTorch and Hugging Face Transformers.
- Halving temperature squares the odds ratio.
- Doubling temperature pulls everyone toward a flat 33/33/33 draw.
How does Nucleus (Top-p) sampling dynamically adapt its truncation pool compared to rigid fixed-size Top-K filtering?
Imagine dining at a buffet with 1,000 dishes. In Top-K sampling with K = 5, the waiter forces you to pick strictly among the top 5 most popular dishes, regardless of what they are. If today's top dish is 99% fresh pizza, the waiter still forces you to consider 4 other dishes you don't want! In Nucleus (Top-p) sampling with p = 0.90, the waiter asks: 'How many dishes does it take to reach 90% of quality?' When the pizza is great (99%), the pool shrinks to 1 single dish. When 20 dishes are all equally good, the pool dynamically expands to 20 dishes. Nucleus sampling breathes with the model's confidence.
- $$Compare rigid top-k thresholding with cumulative probability thresholding sum_{i=1}^V' p_i >= p, showing nucleus sampling expands and contracts dynamically with confidence.$$
- Learning goalImplement Top-K and Nucleus (Top-p) truncation algorithms and evaluate pool size dynamics under varying distribution entropies.
- Helpful foundationsCumulative distribution function · The Curious Case of Neural Text Degeneration (Holtzman et al., 2019)
- Common trapThinking Top-K and Top-p cannot be combined; production engines often apply Top-K first (e.g. K=50) to clip extreme vocab tails, followed immediately by Top-p (p=0.9) for dynamic selection.
- Next connectionWe have now explored the complete probabilistic foundations of loss functions, entropy, and decoding.
More context & mechanics
Let sorted probabilities be p₁ ≥ p₂ ≥ ṡ ≥ p_(|V|).
- Top-K Sampling (Fan et al., 2018):
Truncate the distribution to a fixed integer K:
V^((K)) = 1, 2, ṡ, K
Set all logits outside V^((K)) to -∞ and re-normalize:
qᵢ' = (pᵢ) / (∑_(j=1)^K pⱼ) & if i ≤ K \ 0 & if i > K
- Flaw: When the distribution is flat, K=5 arbitrarily cuts off valid candidates. When the distribution is peaked, K=5 includes unwanted tail garbage.
- Nucleus (Top-p) Sampling (Holtzman et al., 2019):
Find the minimal set of top tokens whose cumulative probability exceeds threshold p ∈ (0, 1) (typically p = 0.90):
V^((p)) = 1, 2, ṡ, k^ where k^ = min k | ∑_(i=1)^k pᵢ ≥ p
- Dynamic Adaptability:
- High Confidence: p₁ = 0.95 ⟹ k^* = 1 (pool collapses to 1 token).
- High Uncertainty: pᵢ = 0.05 ⟹ k^* = 18 (pool dynamically expands to 18 tokens).
Nucleus sampling (Top-p = 0.9) combined with mild temperature (T = 0.7) is the default decoding strategy in OpenAI ChatGPT, Anthropic Claude, and Meta LLaMA.
Ari Holtzman, Jan Buys, Li Du, Maxwell Forbes, and Yejin Choi introduced Nucleus Sampling at ICLR 2020 ('The Curious Case of Neural Text Degeneration'), proving it eliminated repetitive loops and incoherent tail hallucinations.
- Top-K is a rigid box of size K.
- Top-p is a dynamic net that catches 90% of the probability mass.
What is the mathematical foundation and geometric intuition of Temperature Scaling: Softening the Probability Simplex?
Understand Temperature Scaling: Softening the Probability Simplex visually: How temperature T transforms raw logits z = [2.0, 1.0, 0.0] into sampling distributions.. Every transformation preserves core structural invariants while mapping coordinate spaces.
- $$How temperature T transforms raw logits z = [2.0, 1.0, 0.0] into sampling distributions.$$
- Learning goalMaster the algebraic and geometric derivation of Temperature Scaling: Softening the Probability Simplex.
- Helpful foundationsLinear Algebra Fundamentals · Matrix Transformations · Vector Spaces
- Common trapAssuming Temperature Scaling: Softening the Probability Simplex is merely a computational trick rather than an invariant spatial law.
- Next connectionConnects to upstream spectral theory and downstream tensor operations.
More context & mechanics
A comparative decoding probability chart on natural warm linen (#f5f4e9) with a slate border.
Top section: Title in bold sans-serif: "Temperature Scaling: Softening the Probability Simplex". Subtitle: "How temperature T transforms raw logits z = [2.0, 1.0, 0.0] into sampling distributions."
Middle section: Three horizontal probability bar charts side-by-side:
- Cold Temperature (T = 0.5): Probabilities = [0.867, 0.117, 0.016]. Sharp, decisive peak at token 0; near-greedy argmax.
- Standard Baseline (T = 1.0): Probabilities = [0.665, 0.245, 0.090]. Balanced natural language distribution.
- Hot Temperature (T = 2.0): Probabilities = [0.468, 0.316, 0.216]. Flattened distribution; tokens compete evenly.
Show formula: P(wᵢ | z, T) = (exp(zᵢ / T)) / (∑ exp(zⱼ / T)).
Bottom section: Boundary Limits Container: "T → 0: P collapses to Dirac delta δ_(i, argmax(z)) (Hard argmax) | T → ∞: P collapses to Uniform 1/V (Maximum entropy white noise)."
Clear bar charts, generous whitespace, pristine lines.
This principle is foundational across deep learning optimization, high-dimensional representation, and modern LLM architectures.
"Temperature Scaling: Softening the Probability Simplex: Invariance and structure determine stability under spatial and numerical transformations."
What is the mathematical foundation and geometric intuition of The Entropy Monotonicity Theorem: Temperature as Uncertainty?
Understand The Entropy Monotonicity Theorem: Temperature as Uncertainty visually: Mathematical proof that Shannon entropy H(P_T) strictly increases with temperature.. Every transformation preserves core structural invariants while mapping coordinate spaces.
- Learning goalMaster the algebraic and geometric derivation of The Entropy Monotonicity Theorem: Temperature as Uncertainty.
- Helpful foundationsLinear Algebra Fundamentals · Matrix Transformations · Vector Spaces
- Common trapAssuming The Entropy Monotonicity Theorem: Temperature as Uncertainty is merely a computational trick rather than an invariant spatial law.
- Next connectionConnects to upstream spectral theory and downstream tensor operations.
More context & mechanics
A thermodynamic mathematical proof diagram on natural warm linen (#f5f4e9) with a slate border.
Top section: Title in bold sans-serif: "The Entropy Monotonicity Theorem: Temperature as Uncertainty". Subtitle: "Mathematical proof that Shannon entropy H(P_T) strictly increases with temperature."
Middle section: A clean 2D plot of Shannon entropy H in bits against temperature T ∈ [0, 3].
Mark the calculated points from Slide 085:
- H(T = 0.5) = 0.640 bits (Low uncertainty).
- H(T = 1.0) = 1.250 bits (Moderate uncertainty).
- H(T = 2.0) = 1.512 bits (Approaching theoretical maximum log₂(3) = 1.585 bits).
Boxed Derivative Proof:
"(d H(P_T)) / (d T) = (1) / (T²) Var_(P_T)(z) ≥ 0".
Annotate: "Because variance is strictly non-negative (Var(z) ≥ 0), the derivative is unconditionally ≥ 0; temperature is guaranteed to be a monotonic entropy dial."
Bottom section: Card: "Increasing temperature NEVER reduces uncertainty; it is mathematically impossible for an LLM to become more confident as T rises."
Spacious curve layout, sharp mathematical typography, zero clutter.
This principle is foundational across deep learning optimization, high-dimensional representation, and modern LLM architectures.
"The Entropy Monotonicity Theorem: Temperature as Uncertainty: Invariance and structure determine stability under spatial and numerical transformations."
How does Temperature Scaling: Softening the Probability Simplex operate mathematically at scale?
Comparison of three probability distributions from identical logits z = [4.0, 2.0, 1.0]:
- Learning goalMaster the algebraic and geometric derivation of Temperature Scaling: Softening the Probability Simplex.
- Helpful foundationsFoundations of Build Llm From Scratch · Coordinate Invariance & Geometric Projections · Radford et al. (2019), Language Models are Unsupervised Multitask Learners, OpenAI
- Common trapAssuming Temperature Scaling: Softening the Probability Simplex is an arbitrary computational trick rather than an invariant spatial law.
- Next connectionConnects upstream foundational lemmas to modern high-dimensional computational systems.
More context & mechanics
A probability softening trace diagram in square 1:1 format on warm cream parchment (#fcf0db) with a sepia frame.
Top section: Title in navy serif: "Temperature Scaling: Softening the Simplex". Subtitle: "How dividing logits by scalar T controls generation entropy and diversity."
Middle section: Comparison of three probability distributions from identical logits z = [4.0, 2.0, 1.0]:
- Low Temperature (T = 0.2, Greed/Cold):
Scaled logits: [20.0, 10.0, 5.0].
Probabilities: [0.9999, 0.0001, 0.0000]. One-hot collapse; completely deterministic.
- Standard Temperature (T = 1.0, Base):
Scaled logits: [4.0, 2.0, 1.0].
Probabilities: [0.844, 0.114, 0.042]. Balanced selection reflecting raw training distribution.
- High Temperature (T = 2.0, Creative/Hot):
Scaled logits: [2.0, 1.0, 0.5].
Probabilities: [0.551, 0.276, 0.173]. Softened distribution; increases entropy and diversity.
Bottom section: Mathematical limit: "lim_(T → 0) Softmax(z/T) = argmax(z) (Argmax), lim_(T → ∞) Softmax(z/T) = Uniform(1/K)."
Clear bar charts for each temperature level, crisp numeric annotations, balanced square frame.
Every transformation preserves structural invariants while mapping coordinate spaces. When operating in high dimensions, numerical precision and computational efficiency require adhering strictly to canonical mathematical laws.
Formal derivation and peer-reviewed analysis:
Radford et al. (2019), Language Models are Unsupervised Multitask Learners, OpenAI
"Temperature Scaling: Softening the Probability Simplex: Invariance, symmetry, and structure govern mathematical truth across continuous and discrete domains."
How does The Entropy Monotonicity Theorem: Temperature as Uncertainty operate mathematically at scale?
The mathematical derivation:
- Learning goalMaster the algebraic and geometric derivation of The Entropy Monotonicity Theorem: Temperature as Uncertainty.
- Helpful foundationsFoundations of Build Llm From Scratch · Coordinate Invariance & Geometric Projections · Radford et al. (2019), Language Models are Unsupervised Multitask Learners, OpenAI
- Common trapAssuming The Entropy Monotonicity Theorem: Temperature as Uncertainty is an arbitrary computational trick rather than an invariant spatial law.
- Next connectionConnects upstream foundational lemmas to modern high-dimensional computational systems.
More context & mechanics
A mathematical theorem card in square 1:1 format on warm cream parchment (#fcf0db) with an 8px border.
Top section: Title in navy serif: "The Entropy Monotonicity Theorem". Subtitle: "Proof that Shannon entropy H(P_T) is a strictly increasing function of temperature T."
Middle section: The mathematical derivation:
- Define temperature-scaled probability: pᵢ(T) = (e^(zᵢ / T)) / (∑ⱼ e^(zⱼ / T)).
- Define Shannon entropy: H(T) = -∑ᵢ pᵢ(T) log pᵢ(T).
- Compute derivative with respect to temperature:
dH/dT = (1) / (T³) Var_(i ~ p)[zᵢ] = (1) / (T³) ( ∑ᵢ pᵢ zᵢ² - (∑ᵢ pᵢ zᵢ)² ).
- Variance of non-identical logits is strictly positive: Var[z] > 0.
- Therefore: dH/dT > 0 for all T > 0.
Bottom section: Thermodynamic parallel: "As temperature increases, entropy strictly increases. LLM temperature scaling directly mimics Boltzmann thermodynamic entropy."
Elegant LaTeX lines, clean positive variance highlight, balanced square styling.
Every transformation preserves structural invariants while mapping coordinate spaces. When operating in high dimensions, numerical precision and computational efficiency require adhering strictly to canonical mathematical laws.
Formal derivation and peer-reviewed analysis:
Radford et al. (2019), Language Models are Unsupervised Multitask Learners, OpenAI
"The Entropy Monotonicity Theorem: Temperature as Uncertainty: Invariance, symmetry, and structure govern mathematical truth across continuous and discrete domains."