Top-p sampling

누적 확률 샘플링

Sample from the smallest leading set of tokens whose cumulative probability reaches a threshold.

···
html
<div class="scene"><div class="heading">NUCLEUS · p = <span id="p-value">0.70</span></div><div class="nucleus"><div><b>A</b><i style="width:44%"></i><span>44%</span></div><div><b>B</b><i style="width:28%"></i><span>28%</span></div><div><b>C</b><i style="width:16%"></i><span>16%</span></div><div><b>D</b><i style="width:12%"></i><span>12%</span></div></div><div class="muted" id="p-note">A + B · 누적 72%</div></div>
css
.scene{width:min(94vw,800px);height:min(88vh,326px);padding:clamp(10px,2.7vmin,19px);border:1px solid var(--line);border-radius:13px;background:var(--surface);font:500 clamp(13px,2.4vmin,17px)/1.3 var(--font-sans,sans-serif);position:relative;overflow:hidden}.scene .mono{font-family:ui-monospace,SFMono-Regular,monospace}.scene .muted{color:var(--muted)}.scene .accent{color:var(--accent)}.scene .heading{font-weight:750;color:var(--accent);margin-bottom:clamp(5px,1.6vmin,12px)}.nucleus{display:grid;gap:clamp(4px,1.5vmin,9px);height:68%;margin:4px 0}.nucleus div{display:flex;align-items:center;gap:8px;opacity:.38;transition:opacity .3s}.nucleus div.chosen{opacity:1}.nucleus b{width:18px}.nucleus i{display:block;height:clamp(13px,4vmin,23px);background:var(--accent);border-radius:3px}.nucleus span{font-variant-numeric:tabular-nums}.nucleus div.chosen i{background:var(--accent-2)}
js
const rows=[...document.querySelectorAll('.nucleus div')];const states=[[0.5,2,'A + B · 누적 72%'],[0.9,4,'A + B + C + D · 누적 100%'],[0.4,1,'A · 누적 44%']];let step=0;function draw(){const [p,count,note]=states[step];document.getElementById('p-value').textContent=p.toFixed(2);rows.forEach((row,i)=>row.classList.toggle('chosen',i<count));document.getElementById('p-note').textContent=note;step=(step+1)%states.length}draw();setInterval(draw,2200)

Top-p sorts next-token candidates by probability and keeps the leading set until its cumulative mass reaches p. The eligible set shrinks for a sharp distribution and grows for a flatter one.

The demo moves the threshold and highlights eligible bars. Temperature reshapes the distribution, while top-p chooses a subset from it; evaluate their combined effect separately.

When to use

Use it to tune generation variety while excluding low-probability tail candidates.

Open as page ↗