Abstract
Beam search is a desirable choice of test-time decoding algorithm for neural sequence models because it potentially avoids search errors made by simpler greedy methods. However, typical cross entropy training procedures for these models do not directly consider the behaviour of the final decoding method. As a result, for cross-entropy trained models, beam decoding can sometimes yield reduced test performance when compared with greedy decoding. In order to train models that can more effectively make use of beam search, we propose a new training procedure that focuses on the final loss metric (e.g. Hamming loss) evaluated on the output of beam search. While well-defined, this "direct loss" objective is itself discontinuous and thus difficult to optimize. Hence, in our approach, we form a sub-differentiable surrogate objective by introducing a novel continuous approximation of the beam search decoding procedure. In experiments, we show that optimizing this new training objective yields substantially better results on two sequence tasks (Named Entity Recognition and CCG Supertagging) when compared with both cross entropy trained greedy decoding and cross entropy trained beam decoding baselines.
Introduction
Most neural sequence models, such as those used for translation or tagging, are trained using Cross-Entropy (CE) loss. This approach teaches the model to maximize the probability of the correct next word given the previous "gold" tokens. However, at inference time, the model lacks these gold tokens and must rely on algorithms like beam search to explore multiple possible sequences.
This discrepancy creates a "training-inference gap." Because cross-entropy training does not account for the multi-step search process, models often struggle to manage the trade-offs inherent in decoding. In some cases, applying beam search to a CE-trained model can actually degrade performance relative to simple greedy decoding. The primary obstacle to fixing this is that beam search involves discrete "top-k" selection steps, which are non-differentiable and thus incompatible with standard backpropagation.
Methodology: Continuous Relaxation of Beam Search
To bridge the training-inference gap, we introduce a differentiable surrogate for the beam search process. This allows the model to be trained to minimize the final evaluation metric (such as Hamming loss) directly.
Softening the "Top-K" Selection
The core innovation is a "soft" version of the top-k-argmax operation. By utilizing a peaked-softmax function with an adjustable temperature parameter ($\alpha$), we create a probability distribution that concentrates on the top candidates while remaining differentiable.
Soft Backpointers and Losses
Instead of maintaining $k$ discrete sequences, the relaxed beam search maintains a weighted combination of candidates. Each new element in the beam is linked to previous elements via "soft backpointers"—a distribution across all previous beam states. The loss is then calculated at each time step as a weighted average based on these soft distributions. To ensure stability, we employ an annealing strategy, starting with a smooth distribution and gradually sharpening it to mimic hard beam search as training progresses.
Experimental Setup
We evaluated our approach on two natural language processing (NLP) tagging tasks:
- CoNLL 2003 (German): A Named Entity Recognition (NER) benchmark with a small but highly skewed label space.
- CCG Bank: A complex Combinatory Categorial Grammar (CCG) supertagging task featuring a large label space (1,284 labels) and long-range dependencies.
Results and Discussion
The proposed Approximate Direct Loss method ($\tilde{G}_{DL,\alpha}$) significantly outperformed standard cross-entropy baselines across both tasks.
On the CCG Supertagging task, the model achieved a +5.5 accuracy point gain over the locally normalized cross-entropy baseline. In NER, we observed a +1.5 F1 point gain. Notably, while standard beam search often hurts CE-trained NER models, our search-aware training turned beam search into a clear advantage. These results suggest that the model learns to assign scores that ensure the correct sequence remains reachable and highly ranked throughout the entire decoding process, effectively overcoming biases like the "Other" tag bias in NER.
Conclusion and Future Work
By optimizing for the actual evaluation metric through a relaxed beam search, models become "search-aware," focusing on the final output quality rather than local token probabilities. While this method introduces a computational overhead that scales linearly with beam size, it provides a robust path toward end-to-end training of sequence models. Future work will explore adapting this framework to non-decomposable metrics like BLEU and scaling the approach to large-scale tasks like Machine Translation.
Summary updated