The same probabilities can describe prediction loss or ideal code length. Output randomness, stored knowledge, and the value of an answer still require different questions.
Cross-entropy: probability assigned to the observed token
At position t, the model predicts a vocabulary distribution qθ(⋅∣x<t). Write the observed token as a one-hot vector ext. Its loss is
H(ext,qθ)=−logqθ(xt∣x<t).
One-hot encodes one observation; it does not claim that the real data distribution permits only one continuation. At population level, expected cross-entropy decomposes into conditional data entropy and an average conditional KL. On a finite training set, minimizing token negative log-likelihood (NLL) is maximum-likelihood learning.
The same probabilities, supplied to arithmetic coding or ANS, yield lossless code lengths close to NLL. Real compression also accounts for coding overhead, model costs, and shared context. The prediction–compression connection does not make a model file a complete compressor.
Perplexity: a geometric mean inside an exponential
For a fixed evaluation sequence, abbreviate qt=qθ(xt∣x<t) and average over the n scored tokens:
PPL is the geometric mean of the inverse observed-token probabilities, not their arithmetic mean. With natural-log loss, the same value is PPL=eLˉe. Match the exponent base to the loss units.
The three positions assign probabilities 0.5,0.25,0.125 to their observed tokens. They come from different contexts, not one vocabulary distribution. The code lengths are 1,2,3 bits, with a dashed mean of 2 bits and PPL 4. The four equal cells show a uniform four-choice reference with the same PPL, not the original model’s candidate count.
If every observed token receives probability 1/N, PPL is exactly N. This is the precise equal-choice example behind “effective number of options.” For general distributions, PPL is neither a candidate count nor a literal count of alternatives the model hesitates between.
Preparing the visual
What does perplexity actually average?
Turn four observed-token probabilities into code lengths. The dashed line is mean loss. Compare unequal losses with identical PPL, then lower the final token probability to inspect the geometric mean.
Both q=(1/2,1/2,1/2,1/2) and q=(1/4,1,1/2,1/2) assign joint probability 1/16. Mean loss is 1 bit and PPL is 2. Directly averaging the latter sequence's inverse probabilities gives 9/4, which is not its PPL. A low observed-token probability increases NLL; a zero probability makes both loss and PPL infinite.
Compare PPL under matching corpora, tokenization, context lengths, and scoring rules. Across tokenizers, first use common units such as bits per byte with identical raw text and processing. Changing units alone cannot repair a mismatch in evaluation data. PPL reflects the model's cross-entropy rate, not a direct measurement of the true data entropy rate.
KL regularization: why the optimum tilts exponentially
Fix a prompt x and omit it from the notation. The KL-regularized reward objective is
J(π)=Ey∼π[r(y)]−βDKL(π∥πref),β>0.
This is an RLHF objective that methods such as PPO can optimize, not the full PPO algorithm. Its KL direction penalizes placing new probability mass where the reference assigns little. It can limit policy drift without guaranteeing that the reward model is unexploitable or that answers are useful.
For finitely many responses with positive reference probabilities, optimizing over all distributions gives
Start from reference probabilities, multiply by exponential reward weights, then divide by their sum. Equal-reward responses retain their original odds; larger reward gaps or smaller β change the odds more. If the reference has zero probability somewhere, any finite-KL policy must also assign zero there. The formula cannot expand its support.
Preparing the visual
How much probability does a higher reward buy?
Fix reference probabilities and rewards for three responses. Vary β to see exponential tilting by exp(r/β), normalization, expected reward, KL, and the objective.
{"id":"llm-policy","title":"How much probability does a higher reward buy?","summary":"Fix reference probabilities and rewards for three responses. Vary β to see exponential tilting by exp(r/β), normalization, expected reward, KL, and the objective.","height":950,"html":"<p class=\"eyebrow\" data-i18n=\"eyebrow\"></p><h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p>\n<label class=\"control\" for=\"beta\"><span data-i18n=\"control\"></span><output id=\"beta-value\"></output></label><input id=\"beta\" type=\"range\" min=\"25\" max=\"400\" value=\"100\">\n<div class=\"legend\"><span class=\"gray\" data-i18n=\"reference\"></span><span class=\"blue\" data-i18n=\"optimal\"></span></div><div id=\"policy-rows\" class=\"policy-rows\"></div>\n<div class=\"formula\" id=\"normalizer\"></div><div class=\"metric-pair\"><div><span data-i18n=\"reward\"></span><strong id=\"reward\"></strong></div><div><span>KL(π* ∥ πref)</span><strong id=\"kl\"></strong></div></div><div class=\"formula\" id=\"objective\"></div><p class=\"note\" data-i18n=\"note\"></p>\n","css":".intro { margin:8px 0 18px; color:var(--muted); font-size:14px; }\n.control { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-top:18px; }\n.control output { min-width:4em; flex-shrink:0; text-align:center; background:var(--accent-soft); color:var(--accent); padding:2px 8px; border-radius:6px; font-weight:600; }\n.formula { margin-top:18px; padding:14px 0; border-block:1px solid var(--rule); font-size:16px; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }\n.copy-stack { display:grid; margin-top:14px; color:var(--muted); font-size:14px; }\n.copy-stack > * { grid-area:1/1; }\n.copy-stack .reserve { visibility:hidden; }\n.note { margin-top:14px; color:var(--muted); font-size:12px; }\n.metric-pair { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-top:18px; }\n.metric-pair > div { min-width:0; }\n.metric-pair span { display:block; font-size:12px; color:var(--muted); }\n.metric-pair strong { display:block; font-size:24px; font-weight:500; font-variant-numeric:tabular-nums; }\n.scale { display:flex; justify-content:space-between; color:var(--muted); font-size:12px; font-variant-numeric:tabular-nums; }\n@media(max-width:480px) { .metric-pair strong { font-size:21px; } }\n.presets { display:flex; }\n.plot { position:relative; margin-top:18px; height:190px; border-left:1px solid var(--rule); border-bottom:1px solid var(--muted); }\n.plot svg { width:100%; height:100%; overflow:hidden; }\n.plot .curve { fill:none; stroke:var(--accent); stroke-width:2.5; vector-effect:non-scaling-stroke; }\n.plot .curve.secondary { stroke:var(--second); stroke-dasharray:5 4; }\n.scale { position:relative; }.scale .middle { position:absolute; left:50%; transform:translateX(-50%); }\n.formula { font-size:14px; }.formula div+div { margin-top:6px; }\n@media(max-width:480px) { .plot { height:170px; } }\n.plot .curve { transition:d .28s cubic-bezier(.22,1,.36,1); }\n.band { display:flex; height:28px; border-radius:5px; overflow:hidden; background:var(--surface); margin-top:10px; }\n.band > div { background:var(--accent); transition:width .28s ease; }\n.band > .gold { background:var(--second); }\n.legend { display:flex; flex-wrap:wrap; gap:6px 18px; margin-top:10px; font-size:12px; color:var(--muted); }\n.legend .blue::before,.legend .gold::before { content:''; display:inline-block; width:9px; height:9px; border-radius:2px; margin-right:6px; background:var(--accent); }\n.legend .gold::before { background:var(--second); }\n.rows { margin-top:18px; display:grid; gap:12px; }\n.row { display:grid; grid-template-columns:32px 1fr 60px; align-items:center; gap:10px; font-size:13px; }\n.row > div { min-width:0; }.row output { text-align:right; font-variant-numeric:tabular-nums; }\n.track { height:14px; background:var(--surface); border-radius:3px; overflow:hidden; }\n.fill { height:100%; width:0; background:var(--accent); transition:width .28s ease; }\n.presets { flex-wrap:wrap; gap:4px; }.presets button { min-width:0; }\n.metric-pair strong { overflow-wrap:anywhere; }\n.policy-rows { display:grid; gap:18px; margin-top:18px; }.policy-row { border-bottom:1px solid var(--rule); padding-bottom:14px; }.policy-label { display:flex; gap:12px; justify-content:space-between; font-size:13px; margin-bottom:8px; }.policy-label code { color:var(--muted); font-size:12px; }.row { grid-template-columns:45px 1fr 55px; gap:8px; margin-top:5px; }.reference .fill { background:var(--muted); opacity:.45; }.legend .gray::before { content:''; display:inline-block; background:var(--muted); opacity:.45; width:9px; height:9px; margin-right:6px; border-radius:2px; }\n","js":"const $=s=>document.querySelector(s),ref=[.6,.3,.1],rewards=[0,1,2];for(let i=0;i<3;i++)$('#policy-rows').insertAdjacentHTML('beforeend','<div class=\"policy-row\"><div class=\"policy-label\"><strong>'+String.fromCharCode(65+i)+' · r = '+rewards[i]+'</strong><code class=\"weight\"></code></div><div class=\"row reference\"><span>πref</span><div class=\"track\"><div class=\"fill\" style=\"width:'+ref[i]*100+'%\"></div></div><output>'+viz.number(ref[i],3)+'</output></div><div class=\"row optimum\"><span>π*</span><div class=\"track\"><div class=\"fill\"></div></div><output></output></div></div>');\nfunction draw(){const b=+$('#beta').value/100,w=ref.map((p,i)=>p*Math.exp(rewards[i]/b)),z=w.reduce((a,b)=>a+b),q=w.map(v=>v/z),reward=q.reduce((a,p,i)=>a+p*rewards[i],0),kl=q.reduce((a,p,i)=>a+p*Math.log(p/ref[i]),0);$('#beta-value').textContent=viz.number(b,2);document.querySelectorAll('.policy-row').forEach((e,i)=>{e.querySelector('.weight').textContent=viz.number(ref[i],1)+' × e^('+rewards[i]+'/'+viz.number(b,2)+')';e.querySelector('.optimum .fill').style.width=q[i]*100+'%';e.querySelector('.optimum output').textContent=viz.number(q[i],3);});$('#normalizer').textContent='π*(y) = πref(y) e^(r(y)/β) / Z; Z ≈ '+viz.number(z,3);$('#reward').textContent=viz.number(reward,3);$('#kl').textContent=viz.number(kl,3)+' nat';$('#objective').textContent='J* = E[r] − β KL ≈ '+viz.number(reward,3)+' − '+viz.number(b,2)+' × '+viz.number(kl,3)+' ≈ '+viz.number(reward-b*kl,3)+' = β ln Z';}\n$('#beta').addEventListener('input',draw);draw();\n","audio":false,"strings":{"control":"KL penalty weight β","eyebrow":"HOW REWARDS REALLOCATE PROBABILITY","heading":"How much probability does a higher reward buy?","intro":"Fix one prompt and only three possible responses: A, B, C. Reference probabilities are 0.6, 0.3, 0.1 and rewards are 0, 1, 2. All bar widths use a fixed probability scale of 0–1.","note":"Smaller β amplifies reward differences and concentrates mass on C. Larger β keeps the optimum closer to the reference. This solves a finite distribution optimization exactly, with natural-log KL. It is not a PPO training simulation or a guarantee about DPO fitted on finite data.","optimal":"Optimal policy","reference":"Reference","reward":"Expected reward E[r]"}}
Optimality follows directly by substituting logπ∗=logπref+r/β−logZ:
J(π)=βlogZ−βDKL(π∥π∗).
The first term is independent of the chosen π, and the second is nonpositive. Thus π=π∗ maximizes the objective. KL here is in nats; changing the logarithm base requires rescaling its coefficient. A closed-form distribution optimum is not a closed-form neural parameter solution, nor a promise that training reaches it.
How does DPO use this relation?
Rearranging for reward gives
r(x,y)=βlogπref(y∣x)π∗(y∣x)+βlogZ(x).
A Bradley–Terry preference model depends only on reward differences, so logZ(x) cancels for responses to the same prompt. Replacing the policy with a learned πθ gives the DPO loss for a preferred/rejected pair (yw,yl):
It compares log-probability improvements relative to the reference. Standard DPO fits this preference objective directly, without a separate explicit reward model or PPO stage. Its derivation connects to KL regularization, but finite data, parameterization, and optimization errors still matter. DPO and PPO need not produce identical policies, and DPO's β is not a hard budget on the final KL.
Scaling laws: a useful compression view, empirical exponents
Within its model families, data, and fitting range, Chinchilla found that compute-optimal parameter counts and training-token counts should grow roughly together with compute. The common approximation N∝C0.5, D∝C0.5 is not universal across models and training conditions.
Under fixed evaluation settings, decreasing cross-entropy means decreasing ideal average code length. This reframes compute allocation as reducing test cross-entropy. Source-coding theorems alone do not derive the shape or exponents of scaling laws. Finite-context conditional entropy, infinite-history entropy rate, and a fitted constant term are not interchangeable. Architecture, optimization, and data quality still require separate study; see Dense Models and MoE.
The odds formula explains softmax temperature: it scales log-probability differences. Heating makes candidate probabilities more alike; cooling amplifies existing gaps. With fixed logits and no additional truncation, distribution entropy is nondecreasing in temperature. That describes sampling uncertainty, not additional knowledge.
Preparing the visual
Temperature changes odds, not stored knowledge
With four fixed logits, temperature changes odds through exp((zA−zB)/T). Compare unique and tied maxima, inspecting both distribution entropy and loss when B is observed.
{"id":"llm-temperature","title":"Temperature changes odds, not stored knowledge","summary":"With four fixed logits, temperature changes odds through exp((zA−zB)/T). Compare unique and tied maxima, inspecting both distribution entropy and loss when B is observed.","height":950,"html":"<p class=\"eyebrow\" data-i18n=\"eyebrow\"></p><h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p>\n<div class=\"presets\" role=\"group\" data-i18n-label=\"examples\"><button data-mode=\"unique\" data-i18n=\"unique\"></button><button data-mode=\"tied\" data-i18n=\"tied\"></button></div>\n<label class=\"control\" for=\"temperature\"><span data-i18n=\"control\"></span><output id=\"temperature-value\"></output></label><input id=\"temperature\" type=\"range\" min=\"10\" max=\"400\" value=\"100\">\n<div class=\"rows\" id=\"temperature-rows\"></div><div class=\"formula\" id=\"odds\"></div><div class=\"metric-pair\"><div><span data-i18n=\"entropy\"></span><strong id=\"entropy\"></strong></div><div><span data-i18n=\"loss\"></span><strong id=\"token-loss\"></strong></div></div><div class=\"band\" role=\"img\" data-i18n-label=\"strip\"><div id=\"entropy-fill\"></div></div><div class=\"scale\"><span>0 bit</span><span>log₂ 4 = 2 bit</span></div><p class=\"note\" data-i18n=\"note\"></p>\n","css":".intro { margin:8px 0 18px; color:var(--muted); font-size:14px; }\n.control { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-top:18px; }\n.control output { min-width:4em; flex-shrink:0; text-align:center; background:var(--accent-soft); color:var(--accent); padding:2px 8px; border-radius:6px; font-weight:600; }\n.formula { margin-top:18px; padding:14px 0; border-block:1px solid var(--rule); font-size:16px; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }\n.copy-stack { display:grid; margin-top:14px; color:var(--muted); font-size:14px; }\n.copy-stack > * { grid-area:1/1; }\n.copy-stack .reserve { visibility:hidden; }\n.note { margin-top:14px; color:var(--muted); font-size:12px; }\n.metric-pair { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-top:18px; }\n.metric-pair > div { min-width:0; }\n.metric-pair span { display:block; font-size:12px; color:var(--muted); }\n.metric-pair strong { display:block; font-size:24px; font-weight:500; font-variant-numeric:tabular-nums; }\n.scale { display:flex; justify-content:space-between; color:var(--muted); font-size:12px; font-variant-numeric:tabular-nums; }\n@media(max-width:480px) { .metric-pair strong { font-size:21px; } }\n.presets { display:flex; }\n.plot { position:relative; margin-top:18px; height:190px; border-left:1px solid var(--rule); border-bottom:1px solid var(--muted); }\n.plot svg { width:100%; height:100%; overflow:hidden; }\n.plot .curve { fill:none; stroke:var(--accent); stroke-width:2.5; vector-effect:non-scaling-stroke; }\n.plot .curve.secondary { stroke:var(--second); stroke-dasharray:5 4; }\n.scale { position:relative; }.scale .middle { position:absolute; left:50%; transform:translateX(-50%); }\n.formula { font-size:14px; }.formula div+div { margin-top:6px; }\n@media(max-width:480px) { .plot { height:170px; } }\n.plot .curve { transition:d .28s cubic-bezier(.22,1,.36,1); }\n.band { display:flex; height:28px; border-radius:5px; overflow:hidden; background:var(--surface); margin-top:10px; }\n.band > div { background:var(--accent); transition:width .28s ease; }\n.band > .gold { background:var(--second); }\n.legend { display:flex; flex-wrap:wrap; gap:6px 18px; margin-top:10px; font-size:12px; color:var(--muted); }\n.legend .blue::before,.legend .gold::before { content:''; display:inline-block; width:9px; height:9px; border-radius:2px; margin-right:6px; background:var(--accent); }\n.legend .gold::before { background:var(--second); }\n.rows { margin-top:18px; display:grid; gap:12px; }\n.row { display:grid; grid-template-columns:32px 1fr 60px; align-items:center; gap:10px; font-size:13px; }\n.row > div { min-width:0; }.row output { text-align:right; font-variant-numeric:tabular-nums; }\n.track { height:14px; background:var(--surface); border-radius:3px; overflow:hidden; }\n.fill { height:100%; width:0; background:var(--accent); transition:width .28s ease; }\n.presets { flex-wrap:wrap; gap:4px; }.presets button { min-width:0; }\n.metric-pair strong { overflow-wrap:anywhere; }\n.rows .row { grid-template-columns:76px 1fr 55px; }.row:nth-child(2) .fill { background:var(--second); }.row > span { font-size:12px; }.row strong { font-size:14px; margin-right:6px; }\n","js":"const $=s=>document.querySelector(s);let mode='unique';for(let i=0;i<4;i++)$('#temperature-rows').insertAdjacentHTML('beforeend','<div class=\"row\"><span><strong>'+String.fromCharCode(65+i)+'</strong><small></small></span><div class=\"track\"><div class=\"fill\"></div></div><output></output></div>');\nfunction draw(){const t=+$('#temperature').value/100,z=mode==='unique'?[3,2,0,-1]:[3,3,0,-1],w=z.map(v=>Math.exp((v-3)/t)),sum=w.reduce((a,b)=>a+b),p=w.map(v=>v/sum),h=viz.entropy(p);$('#temperature-value').textContent=viz.number(t,2);document.querySelectorAll('.row').forEach((e,i)=>{e.querySelector('small').textContent='z='+z[i];e.querySelector('.fill').style.width=p[i]*100+'%';e.querySelector('output').textContent=viz.number(p[i],3);});$('#entropy').textContent=viz.number(h,3)+' bit';$('#token-loss').textContent=viz.number(-Math.log2(p[1]),3)+' bit';$('#entropy-fill').style.width=h/2*100+'%';$('#odds').textContent='qT(A) / qT(B) = exp((zA − zB) / T) = exp('+ (z[0]-z[1])+' / '+viz.number(t,2)+') ≈ '+viz.number(p[0]/p[1],3);document.querySelectorAll('[data-mode]').forEach(e=>e.setAttribute('aria-pressed',String(mode===e.dataset.mode)));}\n$('#temperature').addEventListener('input',draw);document.querySelectorAll('[data-mode]').forEach(e=>e.addEventListener('click',()=>{mode=e.dataset.mode;draw();}));draw();\n","audio":false,"strings":{"control":"Sampling temperature T","entropy":"Distribution entropy H(qT)","examples":"Logit examples","eyebrow":"LOGIT DIFFERENCES → PROBABILITY RATIOS","heading":"Temperature changes odds, not stored knowledge","intro":"Bars show four candidate probabilities. Gold B is the fixed observed token. Temperature changes the distribution; its entropy and the loss on B are different quantities.","loss":"If B is observed: −log₂ qT(B)","note":"Probability bars use 0–1; entropy uses 0–2 bits. As T→0, a unique maximum gives zero entropy, while tied A and B give 1 bit. As T→∞, all four become uniform with 2-bit entropy. No top-k/top-p truncation is applied. Loss on B illustrates reassigned probabilities, not whole-model PPL.","strip":"Distribution entropy relative to the four-candidate maximum of 2 bits.","tied":"Tied maxima","unique":"Unique maximum"}}
For a proof, use natural logs and write H(qT)=logZT−EqT[z]/T. Differentiating cancels part of the two terms, leaving
dTdHe(qT)=T3VarqT(z)≥0.
As T→0, a unique maximum takes all probability and entropy approaches zero. With m tied maxima, the limit is uniform over those maxima with entropy log2m. As T→∞, the finite vocabulary becomes uniform. If generation also uses top-k, top-p, or other sampling operations, analyze the final distribution rather than applying the untruncated curve unchanged.
Keep different measurements separate
Quantity
What it measures
What it does not establish
Test NLL / PPL
Probability assigned to actual data
Factuality, reliable reasoning, usefulness
Sampling entropy H(qT)
Uncertainty among current candidates
Creativity or additional knowledge
Policy-to-reference KL
Distributional departure
An unexploitable reward or satisfied preferences
Ideal code length
Bits to encode text with a shared model
A complete measure of understanding
Temperature does not edit knowledge stored in weights; low PPL does not automatically remove hallucinations; smaller KL does not mean better alignment. Information theory makes these measurements precise. Factuality, reasoning, and human preferences still need their own evaluations.