In neural text generation, the choice of decoding strategy is as critical as the model architecture itself. Traditional methods often force a trade-off between the reliability of Beam Search and the creativity of Random Sampling. Beam Search, while deterministic, frequently produces repetitive and generic text by pruning diverse candidates too early. Conversely, sampling techniques like Nucleus or Top-p sampling introduce stochasticity, leading to inconsistent results and potential instabilities.
Researchers from Salesforce AI Research, in a paper presented at ACL 2023, introduced Best-k Search (BKS). This algorithm modernizes the classic Best-First Search (BFS) to provide a deterministic decoding strategy that achieves high-quality, diverse outputs without the "stochastic headache" of sampling.
The Limitations of Current Decoding Strategies
Most Large Language Models (LLMs) rely on two primary strategies:
- Beam Search: Maintains a fixed number of the most likely hypotheses. While effective for structured tasks like translation, it often results in "boring" text because it aggressively prunes paths that might lead to more interesting, albeit initially less probable, conclusions.
- Sampling: Introduces randomness to select tokens. While this increases diversity, the lack of determinism makes debugging and consistent deployment difficult.
The core challenge was to develop a deterministic algorithm that matches the diversity of sampling while maintaining the reliability of beam search. Vanilla BFS, which explores the most promising paths regardless of length, was a natural candidate but suffered from poor GPU utilization and a tendency to get stuck in infinite loops.
Methodology: Re-inventing Best-First Search
Best-k Search addresses the shortcomings of BFS through three key technical innovations:
- Parallel Exploration: To leverage GPU batch processing, BKS expands the top $k$ nodes from the priority queue simultaneously. This significantly improves speed compared to the single-node expansion of standard BFS.
- Temporal Decay: To ensure the search eventually terminates, a penalty is applied to older nodes in the frontier. This "soft signal" encourages the algorithm to focus on more recent paths and reach an End-of-Sentence (EOS) token.
- Heap Pruning: Memory is managed by maintaining a maximum frontier size (e.g., 500 nodes), discarding the least promising candidates.
By allowing hypotheses of different lengths to coexist in the search frontier, BKS can explore a 5-word sentence and a 15-word sentence simultaneously, a flexibility that Beam Search lacks.
Experimental Results
The researchers evaluated BKS across tasks including Question Generation (QuoRef, SQuAD), Commonsense Generation (CommonGen), Summarization (XSum), and Machine Translation (WMT’14).
The Quality-Diversity Frontier
A primary finding is that BKS consistently outperforms baselines on the trade-off between quality (measured by ROUGE-1) and diversity (measured by Distinct-1).
On the DROP dataset for Question Generation, BKS produced nearly 10x more unique outputs than standard baselines while maintaining higher grammatical quality. Furthermore, in Machine Translation, using BKS to generate a diverse pool of candidates followed by a reranking step led to significant improvements in BLEU scores over standard Beam Search.
Conclusion and Future Work
Best-k Search demonstrates that randomness is not a prerequisite for diversity. By modernizing Best-First Search with parallelization and temporal decay, BKS provides a robust, deterministic alternative for high-quality text generation. While currently 1.5x to 2x slower than Beam Search due to heap management overhead, its superior performance on the quality-diversity frontier makes it a compelling choice for constrained generation tasks.
Summary updated