Beam search is a search algorithm used in natural language generation to find a high-probability sequence of words, rather than settling for whatever the model considers most likely one word at a time. At each step, instead of keeping only the single best next word, it retains a fixed number of the most promising candidate sequences, the "beam width," and expands each of them before pruning back down to that same number.
This matters because always picking the single most likely next word, a strategy called greedy decoding, can lock a model into a sequence that reads worse overall even though each individual word choice looked reasonable at the time. By tracking multiple candidate sequences in parallel and only committing to one once more of the sentence has been generated, beam search generally produces more coherent, higher-quality output than greedy decoding, at the cost of more computation per step.
