Skip to main content

Beam Search

Beam search is a decoding strategy that explores multiple candidate output sequences simultaneously during text generation, keeping the top-k most probable sequences (the "beam width") at each step. Unlike greedy decoding which always picks the single highest-probability token, beam search considers that a lower-probability token at one step might lead to a better overall sequence.

Example

With beam width 3, the model translating "The cat sat" explores three parallel paths: "Le chat était assis" (prob: 0.85), "Le chat s'est assis" (prob: 0.82), and "Le chat se trouvait assis" (prob: 0.71). It then continues expanding all three before selecting the highest-scoring complete sentence.

Frequently asked questions

What is Beam Search?

Beam search is a decoding strategy that explores multiple candidate output sequences simultaneously during text generation, keeping the top-k most probable sequences (the "beam width") at each step.

Can you give an example of Beam Search?

With beam width 3, the model translating "The cat sat" explores three parallel paths: "Le chat était assis" (prob: 0.85), "Le chat s'est assis" (prob: 0.82), and "Le chat se trouvait assis" (prob: 0.71). It then continues expanding all three before selecting the highest-scoring complete sentence.

Put this into practice

Build polished, copy-ready prompts in under 60 seconds with SurePrompts.

Try SurePrompts