Beam Search
Beam search maintains B (beam width) partial sequences at each step, expanding each with its top-B next tokens and keeping the overall highest-scoring B candidates. It explores multiple paths and returns the highest-probability complete sequence.
What is Beam Search?
Beam search maintains B (beam width) partial sequences at each step, expanding each with its top-B next tokens and keeping the overall highest-scoring B candidates. It explores multiple paths and returns the highest-probability complete sequence.
Beam search maintains B (beam width) partial sequences at each step, expanding each with its top-B next tokens and keeping the overall highest-scoring B candidates. It explores multiple paths and returns the highest-probability complete sequence.
Where is it used?
Beam search is standard in machine translation (T5, MarianMT, Google Translate) and summarization (BART). It is rarely used for open-ended LLM chat (GPT-4, Claude) because it produces generic, less diverse text and is slower than sampling.
How to build it
Maintain a list of (sequence, cumulative_log_prob). At each step, expand each beam with top-B tokens, compute new scores, select top-B overall. Terminate when all beams hit EOS or max length. HuggingFace: `model.generate(num_beams=4)`.