Beam search keeps the b best sequences so far
Interviewers often go past the sampler. Four follow-ups come up: beam search, repetition penalties, min-p and speculative decoding.
Beam search keeps the b best partial sequences by total log-probability, where b is the beam width. Each step extends every one of them by every token and keeps the best b again.
Width 1 is greedy. On the two-step example from the greedy section, a beam of 2 keeps both first tokens and finds the 0.36 pair that greedy missed.
It's the right tool when the input pins the output down, as in translation or summarization. There, repetition and blandness matter less.
Open-ended text is different. Beam search has greedy's problems, worse, because it's a better maximizer:
- Holtzman et al. conclude that maximizing probability is the wrong goal for open-ended text.
- Fan et al. found that beam search tends to produce common phrases and repetitive text from the training set.
- It runs b sequences per prompt, each with its own KV cache, the stored keys and values of the tokens so far.
In the editor are the two-step example's chances again: first for the first token, and second for the token after it. Finish beam(width): set starts, the width most likely first tokens, and pairs, every (first, second, probability) that extends one of them.