How does text become model input, and how do scores become the next token? Follow text → token IDs → logits → probabilities → selection, then compare temperature and candidate filtering. The numerical examples explain decoding; task results determine which settings are useful.
From text to token ID
Tokens are vocabulary units, not equal to characters or words
Text models typically encode strings into sequences of integers, where each integer corresponds to a token in the vocabulary. A token can represent a complete word, part of a word, punctuation, a combination of spaces, or a byte fragment. A single Unicode character may span multiple tokens; conversely, multiple characters may combine into a single token. Therefore, you cannot calculate the input for all models by simply multiplying the number of Chinese characters by two.
BPE (Byte-Pair Encoding) is a common subword construction method. During training, it starts with smaller units and repeatedly merges adjacent units based on corpus statistics. Encoding uses the already trained vocabulary and merge rules, rather than retraining for each input. For example, assuming it has learned to merge in order (l,o)→lo and (lo,w)→low, l o w e r would be tokenized as low e r. This is merely a mechanism example and does not represent the actual tokenization of lower by any existing model.
Byte-level BPE uses a base representation that covers bytes, avoiding issues where a pure character vocabulary lacks certain characters, but the name "BPE" itself does not guarantee byte fallback. Tokenization may also use methods such as Unigram or WordPiece. Normalization, pre-tokenization, and special tokens in the configuration also affect the final result. Tokenizers Model Types
Why counting only the body text is insufficient
Chat systems need to encode roles and message boundaries into the model input. Tool definitions, structured content, images, etc., may also generate additional counts. The string length seen by the user and the model input length belong to different representation layers: first determine how the complete request is constructed, then calculate its token count.
For example, two user messages and combining two texts into one message may have identical body character counts, but the message boundaries may differ. If the tokenizer includes normalization processing, Unicode character sequences that look identical or similar may produce different results; do not assume all tokenizers preserve or eliminate such differences. Tokenization Pipeline
Server-side counts should use the interface corresponding to the target model and be calibrated with actual response usage. Claude's counting documentation also states that counting results are estimates, and counts should be recalculated after model updates; there is no cross-model conversion multiplier that applies to all Chinese, code, and tool schemas. Claude Token counting
From logits to probabilities
Standard autoregressive text generation predicts the next token given the current prefix. The model outputs scores (logits) for each position in the vocabulary; the decoder then selects an ID based on the configuration, appends it to the prefix, and continues. Actual inference engines may use batching or speculative decoding to optimize execution, but the semantics of conditional generation can still be understood through this step-by-step process.
For positive temperature T, a numerically stable way to write softmax is:
Subtracting the maximum value does not change the normalized probabilities but avoids directly calculating huge exponents. Suppose there are only three candidates A, B, C, with logits [2, 1, 0]:
Temperature
A
B
C
T=1
66.52%
24.47%
9.00%
T=0.5
86.68%
11.73%
1.59%
Cooling down amplifies relative score differences, while heating up flattens the distribution. This changes the randomness of selection, it is not a "correctness knob": if the wrong answer originally had the highest score, cooling down will select it more stably. The entire response is not written after a single sample; changes in early tokens will alter the subsequent conditional distribution.
Candidate truncation: top-k and top-p
top-k retains the k candidates with the highest scores; top-p first sorts by probability, retains the smallest prefix where the cumulative probability first reaches the threshold p, and then renormalizes within the retained set. The size of the latter set changes with the distribution.
For the T=1 distribution above, with top-p=0.8, A alone has only 0.6652, which is not enough; adding B reaches approximately 0.9100, so A and B are retained, and C is discarded. Renormalizing gives A≈0.7311, B≈0.2689. top-p=0.8 does not mean retaining 80% of the vocabulary, nor does it mean the highest candidate has an 80% probability.
At T=0.5, A alone exceeds 0.8, so with the same threshold, only A is retained. Therefore, temperature and filtering order jointly affect the results. Different engines may also combine penalties, minimum retention counts, and other filters; you must check the order of specific implementations and cannot assume that parameters with the same name on different services are exactly the same. Transformers Generation Configuration
The independent example below reproduces the values in the table and explicitly adopts the order of "temperature first, then top-p"; no model download is required.
importmathdefsoftmax(logits,temperature=1.0):ifnotlogitsortemperature<=0:raiseValueError("Non-empty logits and positive temperature are required")peak=max(logits)weights=[math.exp((z-peak)/temperature)forzinlogits]total=sum(weights)return[w/totalforwinweights]defnucleus(probs,threshold):ifnot0<threshold<=1:raiseValueError("Threshold should be in (0, 1]")kept, mass=[], 0.0foriinsorted(range(len(probs)),key=lambdai:(-probs[i],i)):kept.append(i)mass+=probs[i]ifmass>=threshold:breakreturn{i:probs[i]/massforiinkept}p=softmax([2,1,0])q=nucleus(p,0.8)assertlist(q)==[0,1]assertmath.isclose(q[0],1/(1+math.exp(-1)))assertnucleus(softmax([2,1,0],0.5),0.8)=={0:1.0}assertmath.isclose(sum(p),1.0)assertlen(nucleus(p,1.0))==3print([round(x,4)forxinp])print({i:round(v,4)fori,vinq.items()})# [0.6652, 0.2447, 0.09]
# {0: 0.7311, 1: 0.2689}
This experiment verifies probability transformations and does not prove that a certain threshold is better for practical tasks. The original research on nucleus sampling discussed probability tails and degeneration issues in open-ended text generation; its results cannot be directly extrapolated to conclude that all tasks such as translation, code, and classification should use the same decoding method. The Curious Case of Neural Text Degeneration
How does probability become a selection?
Treat probabilities as intervals on [0,1): sampling locates u. Filtering must redistribute the intervals; deleting C without renormalization leaves a gap. This visual explains selection from given scores, not the probability of a correct answer.
pi=∑je(zj−maxz)/Te(zi−maxz)/T
Preparing the visual
How does probability become a selection?
Top-p retains the smallest prefix reaching its mass threshold, then renormalizes; the sample position selects one interval.
{"id":"ai-sampling-mass","title":"How does probability become a selection?","summary":"Top-p retains the smallest prefix reaching its mass threshold, then renormalizes; the sample position selects one interval.","height":1000,"html":"<h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p><div class=\"control\"><label for=\"temp\" data-i18n=\"temp\"></label><output for=\"temp\" id=\"temp-value\"></output><input id=\"temp\" type=\"range\" min=\"0.1\" max=\"2\" value=\"1\" step=\"0.1\"></div><div class=\"control\"><label for=\"p\" data-i18n=\"p\"></label><output for=\"p\" id=\"p-value\"></output><input id=\"p\" type=\"range\" min=\"0.05\" max=\"1\" value=\"0.8\" step=\"0.05\"></div><div class=\"control\"><label for=\"u\" data-i18n=\"u\"></label><output for=\"u\" id=\"u-value\"></output><input id=\"u\" type=\"range\" min=\"0\" max=\"0.99\" value=\"0.7\" step=\"0.01\"></div><div class=\"track-row\"><span data-i18n=\"raw\"></span><div id=\"names\" class=\"track\"></div></div><div id=\"raw\"></div><div id=\"filtered\"></div><div class=\"metrics\"><div><span data-i18n=\"kept\"></span><strong id=\"kept\"></strong></div><div><span data-i18n=\"chosen\"></span><strong id=\"chosen\"></strong></div></div><div class=\"copy\"><p id=\"explanation\" role=\"status\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"explain\"></p></div><details class=\"scope\"><summary data-i18n=\"scopeLabel\"></summary><p data-i18n=\"scope\"></p></details>","css":".intro{margin:8px 0 18px;color:var(--muted);font-size:14px}.control{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:6px 12px;align-items:center;margin:14px 0;font-size:13px}.control output{color:var(--accent);text-align:right;font-variant-numeric:tabular-nums;min-width:4em}.control input{grid-column:1/-1;width:100%;margin:0}.presets{display:flex;gap:4px;align-items:stretch}.presets button{flex:1;min-width:0;overflow-wrap:anywhere;font-size:13px;min-height:44px}.actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin:16px 0}.actions button{min-width:0;min-height:44px;font-size:13px;overflow-wrap:anywhere}.copy{display:grid;font-size:14px;margin:16px 0}.copy>*{grid-area:1/1;margin:0;overflow-wrap:anywhere}.reserve{visibility:hidden}.scope{margin-top:14px;color:var(--muted);font-size:12px}.scope summary{padding:8px 0;cursor:pointer}.scope p{margin-top:10px;overflow-wrap:anywhere}.metrics{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px;margin:18px 0}.metrics>div{border-left:2px solid var(--accent);padding:0 6px 0 10px;min-width:0}.metrics span{display:block;min-height:3.6em;color:var(--muted);font-size:12px;overflow-wrap:anywhere}.metrics strong{font-size:21px;display:block;min-height:2em;font-weight:550;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}.check{display:flex;align-items:center;gap:9px;font-size:13px;margin:14px 0}.check input{width:18px;height:18px;flex-shrink:0;accent-color:var(--accent)}select,input[type=text],input[type=number]{background:var(--paper);color:var(--ink);font:inherit;font-size:14px;padding:10px;border:1px solid var(--rule);border-radius:7px;max-width:100%;min-width:0}select{width:100%;min-height:44px}.panel{padding:14px;border:1px solid var(--rule);border-radius:9px;margin:16px 0;min-width:0}.panel>header{font-size:13px;font-weight:600;margin-bottom:12px;color:var(--muted)}.panel>div{overflow-wrap:anywhere}.track-row{margin:16px 0}.track-row>span{display:block;font-size:12px;color:var(--muted);margin-bottom:8px}.track{display:flex;gap:5px;min-width:0}.cell{flex:1;min-width:0;min-height:56px;border:1px solid var(--rule);border-radius:5px;background:var(--surface);display:flex;align-items:center;justify-content:center;text-align:center;padding:6px 3px;font-size:12px;overflow-wrap:anywhere}.cell.on{background:var(--accent-soft);border-color:var(--accent)}.cell.gold{background:var(--second-soft);border-color:var(--second)}.cell.empty{border-style:dashed;color:var(--muted)}.cell.error{border-color:var(--second);text-decoration:line-through}.table{display:grid;gap:5px;font-size:12px}.tr{display:grid;gap:5px}.tr>div{background:var(--surface);border-radius:4px;padding:9px 6px;min-width:0;min-height:5em;overflow-wrap:anywhere;display:flex;align-items:center}.tr>.gold{background:var(--second-soft)}.tr>.on{background:var(--accent-soft)}.formula,.source{font:13px/1.8 ui-monospace,monospace;white-space:pre-wrap;overflow-wrap:anywhere;margin:16px 0}.formula{border-top:1px solid var(--rule);padding-top:12px;min-height:7.2em}.source{min-height:8em;background:var(--surface);padding:12px;border-radius:8px}.intervals{margin:16px 0}.interval{position:relative;height:38px;background:var(--surface);margin:6px 0;border-radius:4px;overflow:hidden}.interval i{position:absolute;height:100%;background:var(--accent-soft);border-left:2px solid var(--accent)}.interval i.gold{background:var(--second-soft);border-color:var(--second)}.interval span{position:relative;z-index:1;font:12px/38px ui-monospace,monospace;padding-left:7px}.bars{display:grid;gap:10px;margin:16px 0}.bar-row{display:grid;grid-template-columns:44px minmax(0,1fr) 62px;gap:8px;align-items:center;font:12px ui-monospace,monospace}.bar-track{height:24px;background:var(--surface);border-radius:4px;overflow:hidden}.bar-track i{display:block;height:100%;background:var(--accent);transition:width .2s}.bar-track i.gold{background:var(--second)}.bar-track i.empty{opacity:.2}.bar-row output{text-align:right}.diagram{display:block;width:100%;height:auto;margin:18px 0}.diagram text{font:13px ui-monospace,monospace;fill:var(--ink)}.node{fill:var(--surface);stroke:var(--rule)}.node.on{fill:var(--accent-soft);stroke:var(--accent)}.node.gold{fill:var(--second-soft);stroke:var(--second)}.edge{stroke:var(--rule);stroke-width:2;fill:none}.edge.on{stroke:var(--accent)}.matrix{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;margin:16px 0}.matrix button{min-width:0;min-height:44px;font:13px ui-monospace,monospace}.matrix button[aria-pressed=true]{background:var(--accent-soft);border-color:var(--accent)}.matrix button.masked{opacity:.35}.legend{font-size:12px;color:var(--muted);min-height:3.6em;overflow-wrap:anywhere}.numeric{font-variant-numeric:tabular-nums}.scope p{line-break:strict}@media(max-width:480px){.presets button,.actions button{font-size:12px}.panel{padding:12px}.metrics{gap:10px}.metrics strong{font-size:19px}.bar-row{grid-template-columns:34px minmax(0,1fr) 58px;gap:6px}}@media(prefers-reduced-motion:reduce){*,*::before,*::after{transition:none!important;animation:none!important}}\n\n.panel>h3{font-size:13px;font-weight:600;margin:0 0 12px;color:var(--muted)}\n\n.bar-row{grid-template-columns:44px minmax(0,1fr) 82px}.bar-row output{white-space:nowrap}@media(max-width:480px){.bar-row{grid-template-columns:34px minmax(0,1fr) 76px}}\n\n","js":"const $=s=>document.querySelector(s);const set=(id,v)=>$('#'+id).textContent=v;const t=k=>viz.t(k);function cells(id,values){$('#'+id).replaceChildren(...values.map(v=>{const e=document.createElement('div');e.className='cell '+(v.cls||'');e.textContent=v.text;e.title=v.title||v.text;return e;}));}function pressed(mode){document.querySelectorAll('[data-mode]').forEach(e=>e.setAttribute('aria-pressed',String(e.dataset.mode===mode)));}const esc=s=>String(s).replace(/[&<>\"']/g,c=>({'&':'&','<':'<','>':'>','\"':'"',\"'\":'''}[c]));const fmt=s=>'{'+[...s].sort().join(', ')+'}';function graph(id,nodes,edges){const el=$('#'+id);el.setAttribute('viewBox','0 0 360 200');el.innerHTML='<defs><marker id=\"arrow-'+id+'\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"5\" markerHeight=\"5\" orient=\"auto-start-reverse\"><path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"var(--muted)\"/></marker></defs>'+edges.map(e=>{const a=nodes[e[0]],b=nodes[e[1]],dx=b.x-a.x,dy=b.y-a.y,d=Math.hypot(dx,dy)||1;if(edges.some(r=>r[0]===e[1]&&r[1]===e[0])){const nx=-dy/d,ny=dx/d;return '<path class=\"edge '+(e[2]?'on':'')+'\" d=\"M '+(a.x+dx/d*22+nx*12)+' '+(a.y+dy/d*22+ny*12)+' Q '+((a.x+b.x)/2+nx*38)+' '+((a.y+b.y)/2+ny*38)+' '+(b.x-dx/d*25+nx*12)+' '+(b.y-dy/d*25+ny*12)+'\" marker-end=\"url(#arrow-'+id+')\"/>';}return '<line class=\"edge '+(e[2]?'on':'')+'\" x1=\"'+(a.x+dx/d*25)+'\" y1=\"'+(a.y+dy/d*25)+'\" x2=\"'+(b.x-dx/d*28)+'\" y2=\"'+(b.y-dy/d*28)+'\" marker-end=\"url(#arrow-'+id+')\"/>';}).join('')+nodes.map(n=>'<g><circle class=\"node '+(n.cls||'')+'\" cx=\"'+n.x+'\" cy=\"'+n.y+'\" r=\"25\"/><text x=\"'+n.x+'\" y=\"'+(n.y+4)+'\" text-anchor=\"middle\">'+esc(n.name)+'</text>'+(n.sub?'<text x=\"'+n.x+'\" y=\"'+(n.y+43)+'\" text-anchor=\"middle\">'+esc(n.sub)+'</text>':'')+'</g>').join('');}function table(id,rows){$('#'+id).classList.add('table');$('#'+id).replaceChildren(...rows.map(r=>{const row=document.createElement('div');row.className='tr';row.style.gridTemplateColumns='repeat('+r.length+',minmax(0,1fr))';r.forEach(x=>{const c=document.createElement('div');if(typeof x==='object'){c.textContent=x.text;c.className=x.cls||'';}else c.textContent=x;row.append(c)});return row;}));}function band(id,parts,total){$('#'+id).replaceChildren(...parts.map((p,i)=>{const e=document.createElement('i');e.style.width=(100*p.value/total)+'%';e.className=i%2?'gold':'on';e.title=p.name+': '+p.value;return e}));}function intervals(id,items,total){$('#'+id).replaceChildren(...items.map(p=>{const row=document.createElement('div');row.className='interval';const bar=document.createElement('i');bar.style.left=(100*p.start/total)+'%';bar.style.width=(100*(p.end-p.start)/total)+'%';bar.className=p.cls||'';const label=document.createElement('span');label.textContent=p.label;row.append(bar,label);return row;}));}function plot(id,series,xr,yr,opts={}){const e=$('#'+id),X=x=>42+(x-xr[0])/(xr[1]-xr[0])*298,Y=y=>175-(y-yr[0])/(yr[1]-yr[0])*148;let out='<defs><clipPath id=\"clip-'+id+'\"><rect x=\"42\" y=\"27\" width=\"298\" height=\"148\"/></clipPath></defs>';for(let i=0;i<3;i++){let x=xr[0]+i*(xr[1]-xr[0])/2,y=yr[0]+i*(yr[1]-yr[0])/2;out+='<path class=\"gridline\" d=\"M '+X(x)+' 27V175M42 '+Y(y)+'H340\"/><text x=\"'+X(x)+'\" y=\"194\" text-anchor=\"middle\">'+esc(opts.xfmt?opts.xfmt(x):Number(x.toFixed(2)))+'</text><text x=\"36\" y=\"'+(Y(y)+4)+'\" text-anchor=\"end\">'+esc(opts.yfmt?opts.yfmt(y):Number(y.toFixed(2)))+'</text>';}out+='<g clip-path=\"url(#clip-'+id+')\">';for(const s of series){out+='<path fill=\"none\" stroke=\"'+(s.color||'var(--accent)')+'\" stroke-width=\"2.5\" '+(s.dash?'stroke-dasharray=\"5 4\"':'')+' d=\"'+s.pts.map((p,i)=>(i?'L':'M')+X(p[0]).toFixed(2)+','+Y(p[1]).toFixed(2)).join(' ')+'\"/>';}for(const p of opts.points||[])out+='<circle cx=\"'+X(p[0])+'\" cy=\"'+Y(p[1])+'\" r=\"4\" fill=\"var(--second)\" stroke=\"var(--paper)\" stroke-width=\"1.5\"/>';if(opts.cursor!==undefined)out+='<path d=\"M'+X(opts.cursor)+' 27V175\" stroke=\"var(--muted)\" stroke-dasharray=\"3 3\"/>';e.innerHTML=out+'</g>';e.dataset.curves=JSON.stringify(series.map(s=>s.pts));}const curve=(fn,lo,hi,n=120)=>Array.from({length:n+1},(_,i)=>{const x=lo+(hi-lo)*i/n;return[x,fn(x)]});function inputs(draw){document.querySelectorAll('input,select').forEach(e=>{e.addEventListener('input',draw);e.addEventListener('change',draw)});draw()}const n=id=>+$('#'+id).value;const show=(id,v,d=3)=>set(id,Number(v.toFixed(d)));function bars(id,values,max=1){$('#'+id).className='bars';$('#'+id).innerHTML=values.map(v=>'<div class=\"bar-row\"><span>'+esc(v.label)+'</span><div class=\"bar-track\"><i class=\"'+(v.cls||'')+'\" style=\"width:'+Math.max(0,Math.min(100,v.value/max*100))+'%\"></i></div><output>'+esc(v.text??(v.value*100).toFixed(1)+'%')+'</output></div>').join('')}function softmax(z,T=1){let max=Math.max(...z),w=z.map(x=>Math.exp((x-max)/T)),sum=w.reduce((a,b)=>a+b,0);return w.map(x=>x/sum)}function draw(){let T=n('temp'),p=n('p'),u=n('u'),a=softmax([2,1,0],T),mass=0,k=0;while(k<3&&(mass<p-1e-12||k===0))mass+=a[k++];let b=a.map((v,i)=>i<k?v/mass:0),c=0,sum=b[0];while(c<2&&u>=sum){c++;sum+=b[c]}['temp','p','u'].forEach(x=>set(x+'-value',n(x).toFixed(2)));cells('names',['A','B','C'].map((text,i)=>({text,cls:i===c?'gold':i<k?'on':'empty'})));bars('raw',a.map((value,i)=>({label:'ABC'[i],value})));bars('filtered',b.map((value,i)=>({label:'ABC'[i],value,cls:i===c?'gold':''})));set('kept',k);set('chosen','ABC'[c]);set('explanation',t('explain'));document.body.dataset.probabilities=JSON.stringify(b);document.body.dataset.raw=JSON.stringify(a);}inputs(draw);","audio":false,"strings":{"chosen":"Selected token","explain":"At T=1 and p=0.8, keep A and B; at T=0.5, A alone reaches the threshold.","filtered":"Retained and normalized","heading":"How does probability become a selection?","intro":"Adjust temperature, top-p and a sample position; compare probabilities before and after filtering.","kept":"Candidates kept","p":"Cumulative threshold","raw":"Original probabilities","reset":"Reset","scope":"Three fixed logits [2,1,0], temperature then top-p, ties A/B/C; you choose the sample position. No model is called.","scopeLabel":"Model scope and assumptions","temp":"Temperature T","u":"Sample position u"}}
Greedy selection and determinism
Greedy takes the highest-scoring candidate at each step. The division formula above is undefined for T=0; some interfaces treat zero temperature as greedy decoding, while others require disabling sampling via a separate parameter. Mathematical limits and interface conventions should be distinguished.
Greedy only guarantees local selection. Suppose at the first step A=0.6, B=0.4, and after selecting A, the best next step probability is 0.5, while after selecting B, the best next step is 0.9. Then the probabilities of the two candidate paths are 0.30 and 0.36 respectively. Step-by-step greedy would first select A, but it did not obtain the path with the higher probability among the two. Beam search retains multiple candidates to mitigate such issues, but is still limited by search width, length bias, and scoring objectives; the highest sequence probability does not equal factual correctness.
For identical logits, argmax with fixed tie-breaking is deterministic; whether real services can produce exactly the same logits again depends on the model version, precision, kernels, batching, and determinism settings. Fixing the seed only controls the corresponding random number process and cannot lock all execution conditions. Low temperature alone cannot promise byte-by-byte reproducibility, and low effort is not a substitute for determinism.
For auditing or regression testing, save the complete input, model and generation configuration, service version information, and raw output. If you must reproduce previously displayed content, you should read the saved result from that time; this is a different guarantee from re-running the model to get the same answer.
Does the best local choice give the best path?
Local choice compares candidates at the current prefix. Move B’s continuation past 0.75: whole-path ranking reverses while greedy still starts with A. The comparison concerns probability, not truthfulness.
Preparing the visual
Does the best local choice give the best path?
A starts at 0.6 versus B at 0.4; above 0.75 on B’s next step, B has the higher two-step path probability.
{"id":"ai-greedy-path","title":"Does the best local choice give the best path?","summary":"A starts at 0.6 versus B at 0.4; above 0.75 on B’s next step, B has the higher two-step path probability.","height":1000,"html":"<h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p><div class=\"control\"><label for=\"next\" data-i18n=\"next\"></label><output for=\"next\" id=\"next-value\"></output><input id=\"next\" type=\"range\" min=\"0.5\" max=\"1\" value=\"0.9\" step=\"0.01\"></div><div id=\"paths\"></div><div class=\"metrics\"><div><span data-i18n=\"greedy\"></span><strong id=\"greedy\"></strong></div><div><span data-i18n=\"best\"></span><strong id=\"best\"></strong></div></div><div id=\"math\" class=\"formula\"></div><div class=\"copy\"><p id=\"explanation\" role=\"status\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"explain\"></p></div><details class=\"scope\"><summary data-i18n=\"scopeLabel\"></summary><p data-i18n=\"scope\"></p></details>","css":".intro{margin:8px 0 18px;color:var(--muted);font-size:14px}.control{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:6px 12px;align-items:center;margin:14px 0;font-size:13px}.control output{color:var(--accent);text-align:right;font-variant-numeric:tabular-nums;min-width:4em}.control input{grid-column:1/-1;width:100%;margin:0}.presets{display:flex;gap:4px;align-items:stretch}.presets button{flex:1;min-width:0;overflow-wrap:anywhere;font-size:13px;min-height:44px}.actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin:16px 0}.actions button{min-width:0;min-height:44px;font-size:13px;overflow-wrap:anywhere}.copy{display:grid;font-size:14px;margin:16px 0}.copy>*{grid-area:1/1;margin:0;overflow-wrap:anywhere}.reserve{visibility:hidden}.scope{margin-top:14px;color:var(--muted);font-size:12px}.scope summary{padding:8px 0;cursor:pointer}.scope p{margin-top:10px;overflow-wrap:anywhere}.metrics{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px;margin:18px 0}.metrics>div{border-left:2px solid var(--accent);padding:0 6px 0 10px;min-width:0}.metrics span{display:block;min-height:3.6em;color:var(--muted);font-size:12px;overflow-wrap:anywhere}.metrics strong{font-size:21px;display:block;min-height:2em;font-weight:550;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}.check{display:flex;align-items:center;gap:9px;font-size:13px;margin:14px 0}.check input{width:18px;height:18px;flex-shrink:0;accent-color:var(--accent)}select,input[type=text],input[type=number]{background:var(--paper);color:var(--ink);font:inherit;font-size:14px;padding:10px;border:1px solid var(--rule);border-radius:7px;max-width:100%;min-width:0}select{width:100%;min-height:44px}.panel{padding:14px;border:1px solid var(--rule);border-radius:9px;margin:16px 0;min-width:0}.panel>header{font-size:13px;font-weight:600;margin-bottom:12px;color:var(--muted)}.panel>div{overflow-wrap:anywhere}.track-row{margin:16px 0}.track-row>span{display:block;font-size:12px;color:var(--muted);margin-bottom:8px}.track{display:flex;gap:5px;min-width:0}.cell{flex:1;min-width:0;min-height:56px;border:1px solid var(--rule);border-radius:5px;background:var(--surface);display:flex;align-items:center;justify-content:center;text-align:center;padding:6px 3px;font-size:12px;overflow-wrap:anywhere}.cell.on{background:var(--accent-soft);border-color:var(--accent)}.cell.gold{background:var(--second-soft);border-color:var(--second)}.cell.empty{border-style:dashed;color:var(--muted)}.cell.error{border-color:var(--second);text-decoration:line-through}.table{display:grid;gap:5px;font-size:12px}.tr{display:grid;gap:5px}.tr>div{background:var(--surface);border-radius:4px;padding:9px 6px;min-width:0;min-height:5em;overflow-wrap:anywhere;display:flex;align-items:center}.tr>.gold{background:var(--second-soft)}.tr>.on{background:var(--accent-soft)}.formula,.source{font:13px/1.8 ui-monospace,monospace;white-space:pre-wrap;overflow-wrap:anywhere;margin:16px 0}.formula{border-top:1px solid var(--rule);padding-top:12px;min-height:7.2em}.source{min-height:8em;background:var(--surface);padding:12px;border-radius:8px}.intervals{margin:16px 0}.interval{position:relative;height:38px;background:var(--surface);margin:6px 0;border-radius:4px;overflow:hidden}.interval i{position:absolute;height:100%;background:var(--accent-soft);border-left:2px solid var(--accent)}.interval i.gold{background:var(--second-soft);border-color:var(--second)}.interval span{position:relative;z-index:1;font:12px/38px ui-monospace,monospace;padding-left:7px}.bars{display:grid;gap:10px;margin:16px 0}.bar-row{display:grid;grid-template-columns:44px minmax(0,1fr) 62px;gap:8px;align-items:center;font:12px ui-monospace,monospace}.bar-track{height:24px;background:var(--surface);border-radius:4px;overflow:hidden}.bar-track i{display:block;height:100%;background:var(--accent);transition:width .2s}.bar-track i.gold{background:var(--second)}.bar-track i.empty{opacity:.2}.bar-row output{text-align:right}.diagram{display:block;width:100%;height:auto;margin:18px 0}.diagram text{font:13px ui-monospace,monospace;fill:var(--ink)}.node{fill:var(--surface);stroke:var(--rule)}.node.on{fill:var(--accent-soft);stroke:var(--accent)}.node.gold{fill:var(--second-soft);stroke:var(--second)}.edge{stroke:var(--rule);stroke-width:2;fill:none}.edge.on{stroke:var(--accent)}.matrix{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;margin:16px 0}.matrix button{min-width:0;min-height:44px;font:13px ui-monospace,monospace}.matrix button[aria-pressed=true]{background:var(--accent-soft);border-color:var(--accent)}.matrix button.masked{opacity:.35}.legend{font-size:12px;color:var(--muted);min-height:3.6em;overflow-wrap:anywhere}.numeric{font-variant-numeric:tabular-nums}.scope p{line-break:strict}@media(max-width:480px){.presets button,.actions button{font-size:12px}.panel{padding:12px}.metrics{gap:10px}.metrics strong{font-size:19px}.bar-row{grid-template-columns:34px minmax(0,1fr) 58px;gap:6px}}@media(prefers-reduced-motion:reduce){*,*::before,*::after{transition:none!important;animation:none!important}}\n\n.panel>h3{font-size:13px;font-weight:600;margin:0 0 12px;color:var(--muted)}\n\n.bar-row{grid-template-columns:44px minmax(0,1fr) 82px}.bar-row output{white-space:nowrap}@media(max-width:480px){.bar-row{grid-template-columns:34px minmax(0,1fr) 76px}}\n\n","js":"const $=s=>document.querySelector(s);const set=(id,v)=>$('#'+id).textContent=v;const t=k=>viz.t(k);function cells(id,values){$('#'+id).replaceChildren(...values.map(v=>{const e=document.createElement('div');e.className='cell '+(v.cls||'');e.textContent=v.text;e.title=v.title||v.text;return e;}));}function pressed(mode){document.querySelectorAll('[data-mode]').forEach(e=>e.setAttribute('aria-pressed',String(e.dataset.mode===mode)));}const esc=s=>String(s).replace(/[&<>\"']/g,c=>({'&':'&','<':'<','>':'>','\"':'"',\"'\":'''}[c]));const fmt=s=>'{'+[...s].sort().join(', ')+'}';function graph(id,nodes,edges){const el=$('#'+id);el.setAttribute('viewBox','0 0 360 200');el.innerHTML='<defs><marker id=\"arrow-'+id+'\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"5\" markerHeight=\"5\" orient=\"auto-start-reverse\"><path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"var(--muted)\"/></marker></defs>'+edges.map(e=>{const a=nodes[e[0]],b=nodes[e[1]],dx=b.x-a.x,dy=b.y-a.y,d=Math.hypot(dx,dy)||1;if(edges.some(r=>r[0]===e[1]&&r[1]===e[0])){const nx=-dy/d,ny=dx/d;return '<path class=\"edge '+(e[2]?'on':'')+'\" d=\"M '+(a.x+dx/d*22+nx*12)+' '+(a.y+dy/d*22+ny*12)+' Q '+((a.x+b.x)/2+nx*38)+' '+((a.y+b.y)/2+ny*38)+' '+(b.x-dx/d*25+nx*12)+' '+(b.y-dy/d*25+ny*12)+'\" marker-end=\"url(#arrow-'+id+')\"/>';}return '<line class=\"edge '+(e[2]?'on':'')+'\" x1=\"'+(a.x+dx/d*25)+'\" y1=\"'+(a.y+dy/d*25)+'\" x2=\"'+(b.x-dx/d*28)+'\" y2=\"'+(b.y-dy/d*28)+'\" marker-end=\"url(#arrow-'+id+')\"/>';}).join('')+nodes.map(n=>'<g><circle class=\"node '+(n.cls||'')+'\" cx=\"'+n.x+'\" cy=\"'+n.y+'\" r=\"25\"/><text x=\"'+n.x+'\" y=\"'+(n.y+4)+'\" text-anchor=\"middle\">'+esc(n.name)+'</text>'+(n.sub?'<text x=\"'+n.x+'\" y=\"'+(n.y+43)+'\" text-anchor=\"middle\">'+esc(n.sub)+'</text>':'')+'</g>').join('');}function table(id,rows){$('#'+id).classList.add('table');$('#'+id).replaceChildren(...rows.map(r=>{const row=document.createElement('div');row.className='tr';row.style.gridTemplateColumns='repeat('+r.length+',minmax(0,1fr))';r.forEach(x=>{const c=document.createElement('div');if(typeof x==='object'){c.textContent=x.text;c.className=x.cls||'';}else c.textContent=x;row.append(c)});return row;}));}function band(id,parts,total){$('#'+id).replaceChildren(...parts.map((p,i)=>{const e=document.createElement('i');e.style.width=(100*p.value/total)+'%';e.className=i%2?'gold':'on';e.title=p.name+': '+p.value;return e}));}function intervals(id,items,total){$('#'+id).replaceChildren(...items.map(p=>{const row=document.createElement('div');row.className='interval';const bar=document.createElement('i');bar.style.left=(100*p.start/total)+'%';bar.style.width=(100*(p.end-p.start)/total)+'%';bar.className=p.cls||'';const label=document.createElement('span');label.textContent=p.label;row.append(bar,label);return row;}));}function plot(id,series,xr,yr,opts={}){const e=$('#'+id),X=x=>42+(x-xr[0])/(xr[1]-xr[0])*298,Y=y=>175-(y-yr[0])/(yr[1]-yr[0])*148;let out='<defs><clipPath id=\"clip-'+id+'\"><rect x=\"42\" y=\"27\" width=\"298\" height=\"148\"/></clipPath></defs>';for(let i=0;i<3;i++){let x=xr[0]+i*(xr[1]-xr[0])/2,y=yr[0]+i*(yr[1]-yr[0])/2;out+='<path class=\"gridline\" d=\"M '+X(x)+' 27V175M42 '+Y(y)+'H340\"/><text x=\"'+X(x)+'\" y=\"194\" text-anchor=\"middle\">'+esc(opts.xfmt?opts.xfmt(x):Number(x.toFixed(2)))+'</text><text x=\"36\" y=\"'+(Y(y)+4)+'\" text-anchor=\"end\">'+esc(opts.yfmt?opts.yfmt(y):Number(y.toFixed(2)))+'</text>';}out+='<g clip-path=\"url(#clip-'+id+')\">';for(const s of series){out+='<path fill=\"none\" stroke=\"'+(s.color||'var(--accent)')+'\" stroke-width=\"2.5\" '+(s.dash?'stroke-dasharray=\"5 4\"':'')+' d=\"'+s.pts.map((p,i)=>(i?'L':'M')+X(p[0]).toFixed(2)+','+Y(p[1]).toFixed(2)).join(' ')+'\"/>';}for(const p of opts.points||[])out+='<circle cx=\"'+X(p[0])+'\" cy=\"'+Y(p[1])+'\" r=\"4\" fill=\"var(--second)\" stroke=\"var(--paper)\" stroke-width=\"1.5\"/>';if(opts.cursor!==undefined)out+='<path d=\"M'+X(opts.cursor)+' 27V175\" stroke=\"var(--muted)\" stroke-dasharray=\"3 3\"/>';e.innerHTML=out+'</g>';e.dataset.curves=JSON.stringify(series.map(s=>s.pts));}const curve=(fn,lo,hi,n=120)=>Array.from({length:n+1},(_,i)=>{const x=lo+(hi-lo)*i/n;return[x,fn(x)]});function inputs(draw){document.querySelectorAll('input,select').forEach(e=>{e.addEventListener('input',draw);e.addEventListener('change',draw)});draw()}const n=id=>+$('#'+id).value;const show=(id,v,d=3)=>set(id,Number(v.toFixed(d)));function bars(id,values,max=1){$('#'+id).className='bars';$('#'+id).innerHTML=values.map(v=>'<div class=\"bar-row\"><span>'+esc(v.label)+'</span><div class=\"bar-track\"><i class=\"'+(v.cls||'')+'\" style=\"width:'+Math.max(0,Math.min(100,v.value/max*100))+'%\"></i></div><output>'+esc(v.text??(v.value*100).toFixed(1)+'%')+'</output></div>').join('')}function softmax(z,T=1){let max=Math.max(...z),w=z.map(x=>Math.exp((x-max)/T)),sum=w.reduce((a,b)=>a+b,0);return w.map(x=>x/sum)}function draw(){let v=n('next'),a=.6*.5,b=.4*v;set('next-value',v.toFixed(2));bars('paths',[{label:'A',value:a},{label:'B',value:b,cls:'gold'}]);set('greedy','A');set('best',Math.abs(a-b)<1e-10?'A = B':a>b?'A':'B');set('math','A: 0.6 × 0.5 = 0.30\\nB: 0.4 × '+v.toFixed(2)+' = '+b.toFixed(3));set('explanation',t('explain'));}inputs(draw);","audio":false,"strings":{"best":"Higher-probability path","explain":"Keep A’s local advantage fixed, then change B’s continuation. Sequence probability multiplies conditional probabilities.","greedy":"Greedy first step","heading":"Does the best local choice give the best path?","intro":"Change the next-step probability on branch B and compare greedy choice with complete path products.","next":"B next-step probability","paths":"Path probabilities","reset":"Reset","scope":"Two equal-length steps, A’s next probability fixed at 0.5; compares the best path in each branch, not factual correctness.","scopeLabel":"Model scope and assumptions"}}
Output stopping and format constraints
Control
What it constrains
What it does not guarantee
EOS or end marker
Model chooses to end
The task has been completed correctly
Max generation length
Upper limit of output size
JSON, code blocks are definitely complete
stop sequence
Stop at specified boundaries
Will not mistakenly truncate the same string in the body
Format or schema constraints
Allowed syntax, fields, or type ranges
Field values are business-true and legal
Repetition penalty
Adjusts scores of already appeared tokens
All repetitions are unnecessary
For example, when generating order JSON, the schema may require quantity to be an integer, but it may not know that the warehouse only has 2 items left. Outputting {"quantity": 5} can be syntactically valid but business-invalid. The client must still check the stop reason, parse completely, execute field validation, and verify inventory and permissions at the business layer.
Repetition penalties also have contextual costs: variable names in code, JSON fields, or fixed terms often need to appear repeatedly; overly strong penalties may destroy consistency. Before selecting sampling parameters, first confirm the output protocol and task constraints. See Prompt Engineering and Structured Output for the complete process of structured output.
Re-establishing baselines during migration
When switching models, separately confirm the tokenizer, chat template, supported generation parameters, and their defaults, then compare length, format pass rate, task accuracy, and result variance on the same task set. Do not infer that a parameter is definitely supported or unsupported based on "local" or "hosted"; rely on the specific model and endpoint. Claude Migration Guide
If the new interface no longer provides temperature, first remove unsupported fields, then use clear task constraints and evaluation to confirm output behavior. Effort adjusts inference investment, temperature adjusts the sampling distribution; the two cannot be numerically mapped. Asking for "four different plans" expresses the output goal but is not equivalent to increasing temperature; asking to "output only one label" is not equivalent to lowering effort. See Reasoning and Thinking for independent trade-offs in inference investment.