Beam Search
A generation strategy where the model does not follow a single path but keeps several hypotheses simultaneously. «Beam» refers to the width of the beam: how many candidates are kept in work.
How It Works
- The model predicts the next word — but instead of taking the single best option, it takes the top-N variants.
- Each variant is continued further.
- At each step, the N best sequences are selected again.
- At the end, the most probable chain is chosen.
Beam Search vs Greedy
| Greedy | Beam Search | |
|---|---|---|
| Keeps hypotheses | 1 | N |
| Quality | Lower | Higher |
| Speed | Faster | Slower |
| Risk | Local optimum | Less |
Where It Is Used
- machine translation;
- subtitles, speech recognition;
- tasks where a smooth, plausible text is important.
Drawbacks
Long beam search generates «uniform» text — language models more often generate through sampling with temperature rather than through beam.