Skip to content
BENIBIX Learn

Beam Search

AI💬 LLMsText Generation

Also known as Beam Decoding, Beam Width

Keeping a few good word paths at once, then taking the best one.

Think of it like

It is like a hiker who keeps the three best paths in mind.

Example

With a beam width of 3, a translation model keeps three draft sentences alive. At the end, it gives back the one with the best total score.

Why it matters

It finds better whole sentences than greedy picking, at the cost of more work.

Definition

Beam search is a way to pick words that keeps several possible texts going at once. At each step it grows every kept text by one token and scores them all. It keeps only the best few, a number called the beam width, and drops the rest. At the end it returns the text with the best total score. It is common in translation, but less common in chat, because it tends to give safe, bland text.
Beam search keeps the best two paths alive here, and the right one wins on its total score.

Common mistake

Thinking a wider beam is always better. Very wide beams can give short, bland answers.

Key takeaways

  1. 1
    Several drafts. Kept at once.
  2. 2
    Beam width. How many drafts survive.
  3. 3
    Best total. Chosen at the end.

Learn it properly