# Beam Search

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

**Field:** Artificial Intelligence  
**Category:** LLMs  
**Also known as:** Beam Decoding, Beam Width

## Think of it like

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

## 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.

## 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.

## Common mistake

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

## Three principles

- **Several drafts.** Kept at once.
- **Beam width.** How many drafts survive.
- **Best total.** Chosen at the end.

## Related terms

- [Greedy Decoding](https://learn.benibix.com/term/ai/greedy-decoding)
- [LLM Sampling](https://learn.benibix.com/term/ai/sampling)
- [Next-Token Prediction](https://learn.benibix.com/term/ai/next-token-prediction)
- [Machine Translation](https://learn.benibix.com/term/ai/machine-translation)
- [Log Probabilities (Logprobs)](https://learn.benibix.com/term/ai/logprobs)

## Taught in

- [Temperature and Sampling](https://learn.benibix.com/learn/ai-llms/temperature-and-sampling): LLMs, 3/15

![A small tree of next words with their chances. Greedy decoding follows one line, always taking the top word. Beam search keeps the two best lines going and picks the better whole sentence at the end.](https://learn.benibix.com/diagrams/ai9-decoding.svg)

---

Source: https://learn.benibix.com/term/ai/beam-search
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
