Abstract: Text generation with beam search has proven successful in a wide range of applications. We point out that, though largely overlooked in the literature, the commonly-used implementation of beam decoding (e.g., Hugging Face Transformers and fairseq) uses a first come, first served heuristic: it keeps a set of already completed sequences over time steps and stops when the size of this set reaches the beam size. Based on this finding, we introduce a patience factor, a simple modification to this beam decoding implementation, that generalizes the stopping criterion and provides flexibility to the depth of search. Empirical results demonstrate that adjusting this patience factor improves decoding performance of strong pretrained models on news text summarization and machine translation over diverse language pairs, with a negligible inference slowdown. Our approach only modifies one line of code and can be thus readily incorporated in any implementation. Further, we find that different versions of beam decoding result in large performance differences in summarization, demonstrating the need for clarity in specifying the beam search implementation in research work. Our code will be available upon publication.
Introduction
In natural language processing, beam search is the standard algorithm for sequence generation. However, a significant gap exists between the "vanilla" beam search described in textbooks and the implementations found in popular libraries like Hugging Face Transformers and fairseq. While researchers often assume vanilla beam search—which continues until the top-$k$ sequences are finished—production libraries typically use a First Come, First Served (FCFS) heuristic. FCFS stops as soon as $k$ completed sequences are found, making the beam size $k$ a single parameter that conflates search breadth and depth. This can lead to suboptimal results, particularly in tasks like summarization where early stopping might favor shorter, lower-quality sentences.
Methods: The Patience Factor
To address this, we introduce a patience factor ($p$), a simple one-line modification to the FCFS stopping criterion. In standard FCFS, the search terminates when the number of finished sequences $|F_t|$ reaches the beam size $k$. Our modification generalizes this to: $$|F_t| \ge k \cdot p$$ By adjusting $p$, we decouple search depth from breadth. A $p > 1$ encourages deeper search, while $p < 1$ favors earlier stopping.
Experimental Setup
We evaluated this approach using pretrained BART and mBART models across Machine Translation (WMT 2020/2021) and Text Summarization (CNN/Dailymail and XSUM) datasets. These tasks cover eight translation directions and two major summarization benchmarks.
Key Insights
Our findings reveal that the "implementation gap" is significant. Vanilla beam search, often cited as the standard, actually underperforms FCFS in summarization. Furthermore, different tasks require different levels of "patience." Machine Translation generally benefits from $p=2$, allowing for more complete translations. In contrast, Summarization performs better with $p=0.5$, which helps mitigate the "beam search curse" where deeper search can lead to repetitive or lower-quality text.
Key Results
The introduction of the patience factor yields measurable improvements with negligible computational cost. On the XSUM summarization task, setting $p=0.5$ improved ROUGE-L from 34.4 to 35.4. In English-to-Polish translation, $p=2$ increased the COMET score from 52.1 to 53.0.
Notably, these gains come with almost no inference slowdown; for $p=0.5$, the process is even faster than the default.
Conclusion
While tested across diverse language pairs, further research is needed for morphologically rich or low-resource languages. We advocate for greater transparency in research regarding the specific beam search implementation used, as these "hidden" details significantly impact reproducibility and performance.
Summary updated