﻿# Beam search compares partial sequences rather than independent next tokens

Beam search keeps several high-scoring partial sequences instead of making one greedy choice. Understand sequence probability, pruning and length penalties.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/beam-search-sequence-probability/
Language: en

Greedy decoding picks one next token and commits to it. Beam search retains several partial continuations, expands them and prunes according to a scoring rule. The mechanism is a search procedure over token sequences. Understanding its objective explains both why it can avoid a local choice and why it does not solve every notion of answer quality.

## A sequence score combines conditional probabilities

An autoregressive sequence probability is a product of conditional token probabilities, commonly represented by a sum of logarithms for computation. A locally most likely token need not begin the highest-scoring complete sequence because later conditional choices differ. Imagine one promising first word followed by weak continuations, while a slightly less likely first word permits a much stronger completion. This schematic example motivates retaining alternatives. It does not imply the search can see all future text without expanding candidates or that the model’s sequence probability is an external truth score.

## Expansion and pruning define the approximation

At a search step, active partial sequences generate candidate extensions. The procedure retains a limited set according to the defined score and handles completed sequences under its stopping policy. Pruned prefixes are no longer explored, so finite beam search is not generally an exhaustive global optimization over every possible answer. Beam width controls candidate retention, not the number of human-interpretable ideas considered. Implementations may include additional restrictions or variants, which should be named rather than inferred from the broad search label.

## Length treatment changes the target objective

Adding log probabilities tends to accumulate nonpositive terms as a sequence grows. Practical generation can use length penalties or normalization and stopping rules to change which completed sequences are favored. These choices are part of the scoring objective, not cosmetic output formatting. Compare two candidate continuations by their actual declared score rather than raw probability alone when a penalty is active. The selected answer can change because the objective changed, even with identical model weights and identical expanded candidate probabilities.

## Evaluate search for the intended application

Beam search can be useful for tasks that favor a high-scoring structured continuation, but probability ranking alone does not establish factual correctness, diversity or conversational usefulness. Preserve beam width, length treatment, constraints and stopping behavior when reproducing results. A tiny vocabulary tree can verify expansion and pruning before measuring full outputs. Compare generated behavior under task-specific criteria, keeping the model fixed. This distinguishes a decoding-search effect from a model-quality change and avoids the unsupported claim that increasing a single search parameter necessarily improves every answer.

## Primary research and implementation references

- [Hugging Face: Generation Strategies](https://huggingface.co/docs/transformers/generation_strategies).

- [The Curious Case of Neural Text Degeneration](https://arxiv.org/abs/1904.09751).

- [Attention Is All You Need](https://arxiv.org/abs/1706.03762).

## Related engineering context

[Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [A GPU inference benchmark you can trust](/journal/inference-benchmark-method/).
