Best-First Beam Search

Clara Meister, Tim Vieira, Ryan Cotterell

TL;DR

Traditional beam search in NLP is computationally inefficient because it explores hypotheses layer-by-layer (breadth-first), wasting time on poor candidates. This paper introduces Best-First Beam Search, a prioritized search strategy that exploits the monotonicity of scoring functions to prune hopeless paths early and terminate the moment the top solution is found. It delivers up to a 10x speedup in practice while mathematically guaranteeing the exact same results as standard beam search.

What Problem Does This Paper Address?

In natural language processing tasks like neural machine translation (NMT) and abstractive summarization, finding the absolute best output sequence (exact decoding) is mathematically intractable due to the exponential size of the search space. To get around this, the community relies heavily on beam search—a heuristic that keeps only the top $k$ most promising partial hypotheses at each token position.

However, standard beam search is fundamentally a breadth-first search (BFS) variant. It forces the decoder to evaluate $k$ hypotheses at length $t$ before it can even look at length $t+1$, regardless of how terrible those length-$t$ candidates are. This creates a significant computational bottleneck, as evaluating these hypotheses requires expensive forward passes through large neural networks. The authors set out to eliminate this waste without sacrificing the quality of the generated text.

Methods

The authors reframe decoding as a generalized agenda-based search algorithm. By adjusting specific "choice points"—such as the priority queue comparator and the stopping criteria—they show how standard algorithms like BFS, Dijkstra, A*, and traditional beam search all belong to the same family.

                       [ General Decoding Scheme ]
                                    |
         -------------------------------------------------------
        |                           |                           |
  (Comparator)             (Stopping Criterion)            (Beam Size k)
        |                           |                           |
  Prioritize by:             Terminate when:               Limit paths per
  - Length (Beam Search)     - All paths hit EOS           length to size k
  - Score (Best-First)       - Top path hits EOS

The core contribution is Best-First Beam Search. Instead of sorting the search agenda by sequence length, the algorithm sorts hypotheses by their cumulative score.

  1. Monotonicity & Early Stopping: For standard log-probability objectives, adding a token can only decrease (or keep equal) the total score. Because scores are monotonically decreasing, the first time a complete hypothesis (ending in an <EOS> token) reaches the top of the priority queue, the algorithm can safely stop and return it. No future extension of any other path can ever beat it.
  2. Pruning Bounded Non-Monotonic Functions: Popular scoring modifications like length normalization and Maximum Mutual Information (PMI) decoding break monotonicity. The authors introduce mathematical upper bounds ($U(x, y')$) for these functions, altering the stopping criteria so that the algorithm still guarantees the identical top-$k$ results as standard beam search.
  3. Memory-Reduced Variant: Best-first search algorithms typically suffer from high memory usage because they track paths across multiple time steps simultaneously. To fix this, the authors introduce a capacity-limited heuristic: when the queue fills up, it aggressively drops the worst-scoring hypothesis from the earliest active time step.

Datasets

The authors evaluated their approach across two major sequence-to-sequence tasks using standard benchmarks:

  • Neural Machine Translation (NMT): Evaluated on the IWSLT’14 De-En (German-to-English), WMT’17 De-En, and MTTT Fr-En (French-to-English) datasets.
  • Abstractive Summarization (AS): Evaluated on the CNN-DailyMail dataset.

Key Insights and Ideas

  • Length Prioritization is an Unnecessary Constraint: We don't need to finish generating all short sentences before looking at longer ones. Sorting strictly by score naturally guides the search down the most promising paths first.
  • Identical Results, Faster Execution: Unlike most speedup heuristics in deep learning that trade away accuracy or BLEU score for performance, Best-First Beam Search is mathematically exact relative to standard beam search. It achieves its speedup purely by avoiding useless computation.
  • The Neural Network is the Bottleneck: The authors emphasize that the computational overhead of managing a more complex priority queue is completely negligible compared to the cost of running a neural network forward pass. Minimizing network calls is the only metric that truly matters for speed.

Key Results

  • Up to 10x Speedups: For standard beam sizes (e.g., $k=5$ or $10$), the best-first approach yields a ~30% reduction in scoring function calls. For larger beam sizes ($k=500$), it achieves an incredible ~10x speedup (reducing calls on IWSLT'14 from 9,770 down to 1,168).
  • Negligible Overhead: As shown in the paper's analysis, the time spent on queue operations does not add noticeable overhead, meaning the reduction in network calls translates directly to wall-clock time savings.
Number of calls to scoring function vs. total sequence generation time across different architectures.
  • Memory-Reduced Success: The memory-reduced variant provided even larger speedups (over 3x for a beam size of 10 on IWSLT'14) while maintaining—and in some cases slightly improving—downstream BLEU scores.

Limitations and Future Work

  • Memory Footprint: In its mathematically exact form, the algorithm must keep track of hypotheses across multiple time steps, leading to a worst-case memory complexity of $O(k \cdot n_{max})$ compared to standard beam search's $O(k)$. While their memory-reduced variant mitigates this, it loses the strict guarantee of exact equivalence to standard beam search.
  • Heuristic Dependencies: When dealing with non-monotonic functions, the performance gains depend heavily on how tight the mathematical upper bounds are. If the bound is too loose, the algorithm cannot stop early as effectively.

Summary updated

BibTeX
@article{meister2020best,
  author = {Clara Meister and Tim Vieira and Ryan Cotterell},
  title = {{Best-First Beam Search}},
  journal = {Trans. Assoc. Comput. Linguistics},
  year = {2020},
  url = {https://openreview.net/forum?id=Hb3AQRkMfb},
}
Figure