Log inStart free
LESSON 29.22 · 6 STAGES · 2 CONTROLS · 2 CHECKSPRO · PREVIEW

Beam search

Watch beam search keep the best few sentences, one token at a time.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 2 controls and 2 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 29.22 · DECODERSTEP 1 · 10 CANDIDATES
01
Stage 1 of 6 · Expand
Beam search extends the prompt “the” by each of the 10 tokens. Each cell holds the log probability log p.
Explain it simply

The chip at the top left is the prompt. The grid below has one cell for each word the model knows. Each cell holds the log of that word's chance, and a number closer to zero means more likely. Here “cat” is the most likely, at minus 0.96.

The prompt chip the sits at the top left. Below it, a row of 10 cells holds log p for each token. The highest is cat at −0.96.

promptkept beams, scorespruned, misseddead end
beams kept per stepcandidates at step 1: 1 × 10 = 10promptthe0after “the”thecatdogsatranonmatrugand.−4.96−0.96−1.16−3.96−3.96−4.46−1.96−2.36−4.96−5.46beams kept per stepcandidates at step 1: 1 × 10 = 10promptthe0after “the”thecatdogsatranonmatrugand.−4.96−0.96−1.16−3.96−3.96−4.46−1.96−2.36−4.96−5.46
Toy: a 10-token bigram model with hand-set logits, 8 steps, scored at T = 1
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
log⁡p(y∣x)=zy−log⁡∑jezj\sy{lp}{out}{\log p(y \mid x)} = \sy{z}{data}{z_y} - \log \textstyle\sum_j e^{\sy{z}{data}{z_j}}
log⁡p(cat∣the)=2.0−2.96=−0.96\log p(\text{cat} \mid \text{the}) = 2.0 - 2.96 = -0.96

Each candidate's log probability is its logit minus the log of the softmax sum.

Common mix-ups

MYTHBeam search always finds the most likely sentence.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
2 CHECKS · PRO
Q01With the prompt “the”, does the final log P go up or down at width 1 instead of 2?

Make your guess, then test it in the diagram. All 2 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 2 live controls
  • 2 mix-up cards and 2 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.