A Continuous Relaxation of Beam Search for End-to-End Training of Neural Sequence Models

Kartik Goyal, Graham Neubig, Chris Dyer, Taylor Berg-Kirkpatrick

Abstract

Neural sequence models are typically trained using cross-entropy loss but decoded at test time using beam search. This discrepancy can lead to suboptimal performance, where beam search occasionally underperforms simple greedy decoding. We present a continuous, differentiable relaxation of the beam search algorithm, enabling end-to-end training that directly optimizes final evaluation metrics. Our "search-aware" training approach demonstrates significant performance gains on structured prediction tasks, including Named Entity Recognition (NER) and CCG supertagging.

Introduction

In sequence-to-sequence (seq2seq) modeling, a significant disconnect exists between training objectives and inference-time decoding. Standard models are trained via locally normalized maximum likelihood (cross-entropy) with "teacher forcing," where the model predicts the next token given the ground-truth history. At inference, however, the model must rely on its own previous predictions. To mitigate error propagation, practitioners employ beam search, maintaining the top-$k$ most probable sequences at each step.

A critical issue is that standard training is not "search-aware." The model does not learn to score sequences in a manner that assists the beam search algorithm in navigating the hypothesis space. Consequently, beam search can sometimes yield worse results than greedy decoding. Ideally, models should be trained by running beam search and penalizing the final output's loss directly. However, the discrete argmax operations in beam search are non-differentiable, preventing optimization via backpropagation.

To bridge this gap, we propose a continuous approximation of beam search that allows gradients to flow through the entire decoding process.

Architecture of the continuous beam search relaxation, showing the differentiable top-k selection and soft backpointer mechanism.

Continuous Top-K Argmax

Standard beam search uses a discrete top-k-argmax to select candidates and establish backpointers. We replace this with a temperature-controlled peaked-softmax function. By squaring the differences between the $i$-th highest score and others and applying a softmax with a temperature parameter $\alpha$, we create a differentiable approximation of top-$k$ selection.

Soft Backpointers and End-to-End Loss

Instead of hard, discrete pointers to previous beam elements, the model maintains "soft backpointers"—a probability distribution over previous beam states. This transformation turns the beam search process into a series of continuous matrix multiplications, making the final sequence loss (e.g., Hamming loss) fully differentiable with respect to model parameters.

Temperature Annealing

To ensure stable gradient flow, we anneal the temperature parameter $\alpha$ during training. We begin with a smoother softmax to facilitate gradient flow and gradually increase $\alpha$ so the function approximates a hard argmax as training converges.

Experimental Setup

We evaluated our approach on two distinct NLP tagging tasks:

  1. Named Entity Recognition (NER): Using the CONLL 2003 German dataset. This task features a small label space (10) and is heavily skewed toward the 'O' (outside) label.
  2. CCG Supertagging: Using the CCGbank. This task has a massive label space (1,284) and requires capturing complex, long-range syntactic dependencies.

Key Results

Our experiments demonstrate that search-aware training effectively resolves beam search pathologies. On the NER task, standard beam search applied to a cross-entropy baseline actually degraded performance compared to greedy decoding. Our continuous beam search training corrected this, allowing the model to leverage the beam for a net gain.

Performance comparison on CCG Supertagging. The proposed search-aware training with annealed temperature achieves the highest accuracy.

As shown in the results for CCG Supertagging, our method achieved a test accuracy of 85.82%, a substantial +5.5 point improvement over the greedy cross-entropy baseline (80.35%). For NER, we achieved a 56.38 Macro F1, a +1.5 point improvement over the greedy baseline (54.92). Notably, applying standard hard beam search to the baseline model dropped performance to 51.34, highlighting the necessity of search-aware training.

Discussion and Limitations

While effective, the proposed method has some limitations:

  • Computational Complexity: Training complexity scales linearly with beam size $k$, making it roughly $k$ times slower than standard cross-entropy training.
  • Loss Decomposability: The formulation currently requires evaluation metrics to be decomposable across time steps (e.g., Hamming loss), complicating direct optimization for metrics like BLEU.
  • Annealing Necessity: We found that annealing is critical; using a fixed, high $\alpha$ leads to flat gradient regions and unstable optimization.

In conclusion, continuous relaxation of beam search provides a robust framework for training search-aware sequence models, successfully aligning training objectives with inference-time behavior.

Summary updated

BibTeX
@inproceedings{goyal2018continuous,
  author = {Kartik Goyal and Graham Neubig and Chris Dyer and Taylor Berg-Kirkpatrick},
  title = {{A Continuous Relaxation of Beam Search for End-to-End Training of Neural Sequence Models}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2018},
  doi = {10.1609/aaai.v32i1.11806},
}
Figure