Every time a language model finishes your sentence, translates a paragraph, or writes a caption for a photo, it faces the same impossible-sounding challenge: pick one sequence of words from an astronomically large space of possibilities. A vocabulary of 50,000 tokens and a sentence of twenty words yields 50, candidates â more arrangements than atoms in the observable universe.
The naive fix is greedy search: at each step, pick the single most likely next token and commit. It is blazing fast, but it is myopic â a locally brilliant choice can trap the decoder in a globally mediocre sentence.
Beam search is the middle path. At every step it keeps not one but K candidates (the "beam"), extending each by every possible next token and then keeping only the K best-scoring continuations. When the beam width K = 1 you get greedy search; as K grows you approach exhaustive search â but even with K = 5 or 10, the algorithm is orders of magnitude cheaper than brute force.
The price is optimality: beam search is not guaranteed to find the highest-probability sequence. The cost is also diversity: a narrow beam can produce repetitive, over-confident output. Yet this controlled approximation has been the dominant decoding strategy in neural machine translation and large language models since around 2015 â a pragmatic bet that the best K candidates carry most of the probability mass.
Comments
Loading comments...