Skip to content
StackDecode
AI & ML Atlas
Artificial IntelligencealgorithmInteractive simulation

Beam Search

Keeps only the best few candidates at each level, trading completeness for speed.

The idea

Breadth-first search that, at every depth, keeps only the best B nodes (the beam width) and discards the rest. Memory stays small and fixed, but the optimal route may be pruned away. It is the standard way to decode text from translation and speech models.

beam size B limits states per level

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

SG
  • current
  • frontier
  • explored
  • path

Walls are dark, brown cells are mud (cost 3), everything else costs 1. Find a route from S to G.

1/57

Compare modes on the same map: A* and UCS find the cheapest route, greedy is fast but can be fooled.

Step by step

  1. 1Start with a beam containing only the start state.
  2. 2Expand every state in the beam to get all successors.
  3. 3Score them and keep only the best B.
  4. 4Repeat until a goal appears in the beam.

Where it is used

Machine translation, speech recognition, text generation.

Watch out for

Width 1 is greedy search; large widths cost more. A narrow beam can miss the best answer completely.

Related