AI GLOSSARY · AI CONCEPTS
Beam search
Definition
Beam search keeps several promising partial output sequences at each step and selects among retained candidates using a configured score. It explores alternatives to greedy decoding, but pruning means it does not guarantee the globally most probable sequence.
Also called: beam search decoding, beam search algorithm, beam width, num_beams, beam decoding.
In plain language
When a language model writes text, it picks one word piece (called a token) at a time. A simple approach takes the most likely piece at every step, like taking the road that looks best at the next junction. Beam search instead follows a few promising routes in parallel and compares the whole routes at the end, so a route that started slightly worse can still win. It does not make answers true: a high-scoring sequence can still be wrong or dull, and following several routes takes more computation than following one.
Technical definition
Beam search heuristically extends and prunes partial sequences to a beam width. Scoring commonly accumulates token log probabilities, with settings such as length penalties changing the ranking. In Hugging Face Transformers, num_beams=1 with do_sample=False is greedy decoding; with do_sample=True it is sampling. num_beams>1 enables beam search without sampling when do_sample=False, or beam sampling when do_sample=True. Pruning can discard a prefix leading to the global optimum. The cited translation paper also explores adaptive beam sizes.
Worked examples in this catalogue
Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.
Guide · Illustrative, not executed
What Is an LLM? The Facts Agent Users Need
- What you see
- A guide explaining how a language model relates to the application around it and why generated answers need checking.
- Why it exercises the concept
- Decoding settings such as beam width belong to the layer between model and application. The guide gives the context for that split; it does not cover beam search itself, and the catalogue has no decoding skill.
Skill by Skill Almanac · Illustrative, not executed
llm-eval-test-sets 57/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- The skill builds and validates an eval dataset for any LLM feature, with a checker for duplicates, missing graders, imbalance and leakage.
- Why it exercises the concept
- Comparing a beam setting with another decoding setting needs a fixed set of test cases. This skill is about building that set; it does not run beam search. Illustrative only.
Skill by Skill Almanac · Illustrative, not executed
local-model-sizing 57/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- The skill works out whether an open-weight language model will run on a given GPU, Mac or PC, with a script that computes weight, KV-cache and overhead memory per quantization.
- Why it exercises the concept
- Local runs are where a reader can choose decoding options. Per the Hugging Face guide, beam search tracks several sequences at once; this skill does not model that cost, so treat its estimate as a starting point.
How it shows up when you use agents
Most users of these tools do not set a beam width. Beam search matters when you run an open model yourself, for example through the Hugging Face Transformers library, where num_beams>1 selects a beam-based mode and do_sample distinguishes deterministic beam search from beam sampling.
Beam search sits in the inference stage: the model assigns probabilities to the next token, and the decoding method turns those probabilities into text. Hugging Face describes greedy search as the default, and says beam search is best suited to input-grounded tasks such as describing an image or speech recognition. The same documentation says sampling can generate more creative and diverse outputs.
What breaks when it is misunderstood: a reader may assume a wider beam gives a more correct answer. It selects among retained candidates under the configured score; a wider beam does not guarantee a higher-probability sequence or factual correctness. A wider beam also means more candidates are tracked per step, so budget more compute.
Next action: if you self-host a model, compare a small beam with num_beams=1 under explicitly recorded sampling and scoring settings on your own evaluation cases before changing a default. See autoregressive model for how text is produced one token at a time.
Common confusions
- Beam search versus greedy search. Greedy search takes the most likely token at each step. Beam search keeps several sequences and can pick one whose first tokens were less likely. In the Transformers API, num_beams=1 is greedy only when do_sample=False; otherwise it samples.
- Beam search versus sampling. Sampling picks tokens at random from the probability distribution. Beam search is a search for a high-probability sequence. The two can be combined, but beam search still prunes low-probability sequences between steps.
- Highest probability versus best answer. The score derives from model probabilities and decoding settings, including possible length penalties. It is not a check against facts, so see hallucination.
- Fixed versus flexible beams. The classic version keeps a fixed number of candidates per step. The Freitag and Al-Onaizan paper proposes varying the number by score for translation decoding.
Related terms
Terms that mention Beam search
3 terms mention this one
More in AI concepts
Sources
- Generation strategies (Transformers documentation), Hugging Face (accessed 2026-11-24)
- Beam Search Strategies for Neural Machine Translation - Freitag and Al-Onaizan, arXiv (accessed 2026-11-24)
- Generation: decoding modes and length_penalty, Hugging Face Transformers (accessed 2026-11-25)
Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-25. Wikipedia is never the only source.
Review record
Last verified
Drafted by Claude (original draft); OpenAI Codex (bounded factual repairs); sources and example targets checked by Independent automated source review (OpenAI Codex); not human peer review on 2026-11-25. Last verified .
Change log (5)
- : Independent automated factual/example review completed. Cached US query estimate aligned to receipt; no traffic promise. Final technical gate recorded separately; publication disabled.
- : First version.
- : Verifier pass: removed banned absolute and the unsourced hosted-service sentence.
- : Bounded source repairs: Specified beam/sampling mode conditions and configured sequence scores; removed global-optimum and wider-always-higher implications. Pending independent re-review.
- : Automated review completed; approved for the staged public release. Search indexing is controlled by the release configuration.