Beam search is a sequence-decoding method that explores several partial token sequences, expands them, and retains only the highest-scoring candidates. section 5.2.2
A beam-search loop follows four practical steps:
- Initialize the beam with the k most likely starting tokens. section 5.2.2
- Expand every candidate by appending its k most probable next tokens. section 5.2.2
- Score each expanded sequence using its cumulative probability and keep the top k. section 5.2.2
- Stop when the maximum length is reached or every candidate emits an end-of-sequence token. section 5.2.2
Beam width two
To generate “the quick brown fox,” begin with “the” and “a.” Expand them to “the quick,” “the cat,” “a dog,” and “a cat,” then retain the two highest-scoring sequences. Expand those again, for example producing “the quick brown” and “the cat sat,” and continue until termination. section 5.2.2
Figure 5.4 Beam search starting with two candidates, “the” and “a.” Two candidate sequences are highlighted, each with a calculated cumulative probability based on the probabilities of the individual words within the sequence.
Use the candidate-sequence figure to inspect how two starting hypotheses receive cumulative-probability scores during search. section 5.2.2






