Beam search decoding generates text by maintaining multiple candidate sequences in parallel and extending each with its most promising next tokens at every step, pruning down to only the highest-scoring sequences to keep the search computationally tractable, in contrast to the single-sequence, no-lookahead approach greedy decoding uses or the randomness-driven approach sampling-based methods use. Beam search is generally favored for tasks like machine translation, where a single well-optimized, high-scoring output sequence is desired, over sampling-based methods, which are generally favored where output diversity across multiple generations matters more than optimizing a single best sequence.