Beam Search › Diverse Beam Search
Language AI HandbookAll chapters Beam Search › Diverse Beam SearchOne section · Sections in this chapter7 / 17 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Standard beam search tends to produce hypotheses that are very similar to each other. When the model is confident about the first few tokens, all beam hypotheses will start with the same token, diverging only in later positions. The beam is homogeneous rather than diverse.
This is a problem in applications that need multiple distinct outputs, such as generating several translation candidates for a human post-editor to choose from, or generating multiple image captions and selecting the best one. When a human reviewer receives five near-identical outputs, the "top-k best" functionality provides little benefit. What is needed is outputs that represent clearly different ways of completing the task.
The Grouping Approach
Diverse beam search (Vijayakumar et al., 2018) addresses this by partitioning the beams into groups, each of size . Within each group, standard beam search runs. Between groups, a diversity penalty discourages groups from producing similar tokens.
At each step , for group , the score for token is:
where:
- : the model's log-probability for token
- : the diversity strength hyperparameter
- : a diversity penalty measuring how many hypotheses in earlier groups already chose token at this step
The penalty encourages each group to select tokens that prior groups have not chosen, spreading the search across different parts of the output space. The first group runs without penalty. The second group is penalized for tokens chosen by the first group. The third group is penalized for tokens chosen by the first two, and so on.
With , diverse beam search reduces to standard beam search. Larger values of force more diversity but may reduce the individual quality of each output.
The grouping mechanism has an intuitive interpretation. Think of each group as a different "opinion" about how the sequence should start. Group 1 follows the most probable path. Group 2 is forced to explore a different starting direction. Group 3 explores a third direction. By the end of decoding, you have distinct hypotheses, one from each group, that cover a broader range of the output space than hypotheses from standard beam search.
Stochastic Beam Search
Another approach to diversity is stochastic beam search, which introduces randomness into the candidate selection step. Instead of deterministically keeping the top candidates, stochastic beam search samples the survivors according to their scores, using a Gumbel noise perturbation. Concretely, it adds i.i.d. Gumbel noise to each candidate score before selecting the top :
This corresponds to sampling without replacement from the categorical distribution defined by the candidates' scores. The result is a diverse set of hypotheses while still being biased toward high-scoring candidates. Stochastic beam search interpolates between deterministic beam search (no noise) and pure sampling (infinite noise).