Beam Search
A search algorithm used in text generation that explores multiple candidate sequences simultaneously, keeping the top-K most promising options at each step.
How It Works
At each generation step, instead of keeping only the most likely token (greedy search), beam search maintains K candidates (the beam width). Each candidate is extended, scored, and the top K are kept. The best complete sequence is returned.
Pros and Cons
Pros: Produces more coherent, higher-quality text than greedy decoding. Finds better overall sequences. Cons: More computationally expensive. Can produce repetitive, generic text. Less creative than sampling methods.
Modern Usage
Used primarily in machine translation and structured generation. For creative text and chatbots, sampling methods (temperature, top-p, top-k) are preferred as they produce more diverse, natural-sounding responses.