Improved Lexically Constrained Decoding for Translation and Monolingual Rewriting

J. Edward Hu, Huda Khayrallah, Ryan Culkin, Patrick Xia, Tongfei Chen, Matt Post, Benjamin Van Durme

Abstract

Lexically constrained decoding—forcing specific words or phrases to appear in neural machine translation (NMT) output—is critical for domain adaptation and terminology control. However, existing methods like Dynamic Beam Allocation (DBA) are computationally expensive and struggle with overlapping constraints. This paper introduces Vectorized Dynamic Beam Allocation (VDBA), achieving a 5x speedup through GPU-native batching. By employing multi-state tries, the method also resolves logical ambiguities in constraint tracking. We demonstrate the efficacy of this approach by using constrained paraphrasing as a robust data augmentation tool for NLI, QA, and MT tasks.

Introduction

Controlling the output of neural models through "hard" constraints is a common requirement in NLP, such as enforcing technical terminology or preventing offensive language. While negative constraints (exclusion) are trivial to implement, positive constraints (inclusion) present significant challenges. Previous state-of-the-art methods, notably Dynamic Beam Allocation (DBA), were limited by sequential processing and failures in "corner cases" where constraints shared prefixes (e.g., "a horse" and "a cow"). These limitations made constrained decoding impractical for large-scale applications like data augmentation.

Methodology

The proposed improvements focus on two key areas: computational efficiency and logical robustness.

Vectorized Dynamic Beam Allocation (VDBA)

To overcome the batching bottleneck of original DBA, the authors redesigned the algorithm for GPU-native matrix operations. VDBA assembles a hypothesis matrix and utilizes a multi-key sort—prioritizing sentence ID, then the number of unmet constraints, and finally sequence score—to efficiently allocate beam slots across an entire batch.

Multi-state Tries

Instead of flat arrays, the decoder uses a trie (prefix tree) to track constraint fulfillment. This allows the system to maintain multiple potential matches simultaneously. For instance, if a hypothesis generates the word "a," the trie keeps both "a horse" and "a cow" active until subsequent tokens disambiguate the match.

Multi-state trie for constraints 'a horse' and 'a cow'.

This structure also handles more complex scenarios, such as nested constraints or constraints that share internal sequences, ensuring that the decoder does not "forget" a constraint if it overlaps with another.

Trie structure for nested constraints 'small cat' and 'a small bird'.

Experimental Results

The authors evaluated VDBA across several benchmarks, including PARABANK for paraphrasing, MultiNLI for inference, and WMT datasets for translation.

  • Throughput: VDBA achieved a 5.1x speedup compared to the baseline DBA with a batch size of 20, making it practical for large-scale rewriting.
  • Translation Quality: On German-English translation, the method improved BLEU scores by up to 2.0 points, attributed to more accurate constraint placement.
  • Data Augmentation: In NLI tasks, augmenting training data with constrained paraphrases led to a gain of 0.9 F1 points. In QA tasks (TREC-QA), a "voting" mechanism across paraphrases improved Mean Average Precision (MAP) by approximately 3%.

Conclusion

Vectorized Dynamic Beam Allocation makes lexically constrained decoding practical for large-scale production and research. By fixing the logical flaws of previous trie-less methods and optimizing for GPU hardware, the authors have turned constrained decoding into a viable tool for data augmentation. Future work may explore more sophisticated rewriting strategies beyond simple lexical constraints to further enhance model robustness.

Summary updated

BibTeX
@inproceedings{hu2019improved,
  author = {J. Edward Hu and Huda Khayrallah and Ryan Culkin and Patrick Xia and Tongfei Chen and Matt Post and Benjamin Van Durme},
  title = {{Improved Lexically Constrained Decoding for Translation and Monolingual Rewriting}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2019},
  doi = {10.18653/v1/n19-1090},
}
Figure