ContentsThe library

How a Model Picks Its Next Word

What a Beam Keeps, and What It Costs

Last timeThe Likeliest Word Is Not the Likeliest Sentence

Beam search is greedy selection applied to sets instead of tokens. Writing its score out reveals a bias towards short sequences, and the standard repair introduces a bias of its own.

Beam search was described in one sentence in the previous lesson: keep the best

bb partial sequences, extend them all, keep the best bb again. Writing down

the score being compared shows where its known biases come from.

The score is a sum

Probabilities of long sequences underflow, so beam search accumulates logarithms

instead.

FIG 1The score of a partial sequence
the running score, always negative and always decreasing
the logarithm of the probability of one token, a negative number
The ordering is identical to the ordering by probability, since the logarithm is increasing. What has changed is that the objective is now a sum of negative terms, so the act of continuing a sequence is itself penalised.

Every token makes it worse

That last point is worth dwelling on. Since each term is negative, a longer

sequence scores lower than a shorter one, other things being equal. Between two

finished candidates, one of six tokens and one of twelve, the six-token one

starts with an advantage that has nothing to do with quality.

The lesson stops here

7 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Model Does Not Write Anything
  2. 02Two Different Questionsopening only
  3. 03What a Beam Keeps, and What It Costsyou are here
  4. 04What Temperature Actually Doesopening only
  5. 05Throwing Away the Worst Optionsopening only
  6. 06The Loop Is the Most Probable Continuationopening only
  7. 07Making the Output Fit a Formatopening only
  8. 08Guessing Ahead Without Changing the Answeropening only

Read alongside