# What is Beam Search? Beam search is a decoding strategy that maintains several candidate sequences in parallel, extending each by the most likely next tokens and keeping only the top scoring candidates at every step. The number retained is called the beam width. It finds higher-probability sequences than greedy decoding at proportionally higher compute cost. At each step the algorithm expands every surviving candidate with plausible continuations, scores the resulting sequences by cumulative log probability, and prunes back to the beam width. When a candidate emits an end token it is set aside as complete. The best-scoring completed sequence is returned once enough candidates have finished or a length limit is reached. The method directly attacks greedy decoding's myopia by deferring commitment. A path that looks weaker after two tokens can still win if it leads somewhere better, provided it stays inside the beam. Wider beams search more thoroughly, but returns diminish quickly and cost rises roughly in proportion to width in both compute and memory. Raw cumulative probability penalizes long sequences, since every additional token multiplies in another probability below one. Length normalization divides by sequence length, often with a tunable exponent, to counteract this. Without it, beam search systematically prefers short outputs, which is a well-documented failure in translation and summarization systems. Beam search dominates constrained tasks such as translation and speech transcription, where a single best answer exists and finding it matters. It has largely fallen out of favor for open-ended chat generation, where it tends to produce safe, repetitive text that scores well on probability but reads poorly. Sampling methods are preferred there. ## Key points - Keeps several candidate sequences alive at once - Beam width trades search quality against compute - Needs length normalization or it favors short outputs - Strong on translation and transcription tasks - Produces bland, repetitive text on open-ended generation ## In practice A transcription system hears an ambiguous phrase that could be "recognize speech" or "wreck a nice beach". Greedy decoding commits to whichever first word scores higher and is stuck. With a beam width of five, both paths survive the first two tokens; by the third, the language model strongly favors the first reading, and the cumulative score separates them clearly. The system returns the better full sequence rather than the better first guess. ## Related terms - [Greedy Decoding](/en/glossary/greedy-decoding) - [Temperature](/en/glossary/temperature) - [Top-p Sampling](/en/glossary/top-p-sampling) - [Encoder-Decoder Model](/en/glossary/encoder-decoder-model) - [Inference](/en/glossary/inference) [Back to the AI Glossary](/en/glossary)