SlowGuess/ACL_2020_OCR huggingface dataset:
Raymond Hendy Susanto, Shamil Chollampatt, and Liling Tan
Rakuten Institute of Technology Singapore
Rakuten, Inc.
{first.last}@rakuten.com
This paper proposes a simple and effective algorithm for incorporating lexical constraints in neural machine translation. Previous work either required re-training existing models with the lexical constraints or incorporating them during beam search decoding with significantly higher computational overheads. Leveraging the flexibility and speed of a recently proposed Levenshtein Transformer model (Gu et al., 2019), our method injects terminology constraints at inference time without any impact on decoding speed. Our method does not require any modification to the training procedure and can be easily applied at runtime with custom dictionaries. Experiments on English-German WMT datasets show that our approach improves an unconstrained baseline and previous approaches.
Neural machine translation (NMT) systems can generate higher-quality translations than phrase-based MT systems, but they come at the cost of losing control over how translations are generated. Without the explicit link between the source and the target vocabulary, enforcing specific terminological translation in domain-specific settings becomes painfully difficult for NMT systems. Consider an example where we have a Chinese-English NMT system trained for the E-commerce domain, and there is no prior knowledge of the brand name "红米" in the training data, the system would translate the input term literally as "red (红) rice (米)" instead of "Redmi". In such scenarios, machine translation users often maintain in-domain dictionaries to ensure that specific information is translated accurately and consistently.
A line of previous work that tried to address this problem required re-training the NMT models with lexical constraints, either by a placeholder mecha
nism (Crego et al., 2016) or via code-mixed training (Song et al., 2019; Dinu et al., 2019). However, they do not reliably guarantee the presence of the constraints at test time. Another approach focused on constrained beam search decoding (Hokamp and Liu, 2017; Post and Vilar, 2018; Hu et al., 2019). Although the latter approach has higher control over the target constraint terms, they significantly slow down the decoding.
Different from the existing line of work, we invoke lexical constraints using a non-autoregressive approach. To do this, we use Levenshtein Transformer (LevT) (Gu et al., 2019), an edit-based generation model that performs deletion and insertion operations during inference iteratively. LevT achieves substantially higher inference speed compared to beam search without affecting quality. We add a constraint insertion step in LevT decoding to seamlessly decode the target language sequence while adhering to specific lexical constraints, achieving the same speed as standard LevT decoding.
Previous approaches integrated lexical constraints in NMT either via constrained training or decoding. Crego et al. (2016) replaced entities with placeholders that remained unchanged during translation and placed them back in a post-processing step. Song et al. (2019) trained a Transformer (Vaswani et al., 2017) model by augmenting the data to include the constraint target phrases in the source sentence. Dinu et al. (2019) proposed a similar idea and additionally used factored training. Other approaches proposed enforcement of lexical constraints during inference with various improvements to constraint-aware beam search, such as
<sup>1</sup>In literature, non-autoregressive NMT decoding mostly refers to those that do not generate tokens sequentially, although they perform iterative refinement (Lee et al., 2018).
Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 3536-3543 July 5 - 10, 2020. ©2020 Association for Computational Linguistics
grid beam search (Hokamp and Liu, 2017), dynamic beam allocation (Post and Vilar, 2018), and its optimized vectorized version (Hu et al., 2019). Hasler et al. (2018) built finite-state acceptors to integrate constraints in a multi-stack decoder. These lexically-constrained decoding approaches rely on autoregressive inference that generates one target token at a time, which makes it difficult to parallelize the decoder and monotonically increases decoding time. While being mostly effective at forcing the inclusion of pre-specified terms in the output, these approaches further slow down the beam search process. Post and Vilar (2018) reported  $3 \times$  slow down compared to standard beam search.
Non-autoregressive neural machine translation (NAT) (Gu et al., 2018) attempts to move away from the conventional autoregressive decoding. Such a direction enables parallelization during sequence generation that results in lower inference latency. Recent NAT approaches treat inference as an iterative refinement process, first proposed by Lee et al. (2018). Following this direction, it is intuitive to perform decoding using "edit" operations, such as insertion (Stern et al., 2019) or both insertion and deletion (LevT, Gu et al. (2019)). The LevT model has been shown to outperform existing refinement-based models, such as Ghazvininejad et al. (2019) and performs comparably to autoregressive Transformer models. Our method integrates lexical constraints in NAT decoding utilizing the flexibility, speed, and performance of LevT.
3 Levenshtein Transformer
Levenshtein Transformer (LevT) (Gu et al., 2019) has an encoder-decoder framework based on Transformer architecture (Vaswani et al., 2017) with multi-headed self-attention and feed-forward networks. Unlike token generation in a typical Transformer model, LevT decoder models a Markov Decision Process (MDP) that iteratively refines the generated tokens by alternating between the insertion and deletion operations. After embedding the source input through a Transformer encoder block, the LevT decoder follows the MDP formulation for each sequence at the  $k$ -th iteration  $\mathbf{y}^k = (y_1, y_2, \dots, y_n)$ , where  $y_1$  and  $y_n$  are the start  $(
)$  and end  $(
)$  symbols. The decoder then generates  $\mathbf{y}^{k+1}$  by performing deletion and insertion operations via three classifiers that run sequentially:
Figure 1: Levenshtein Transformer decoding with lexical constraints for English-German MT. The source sentence is Nevada has completed a pilot project. and the target constraints are [Nevada, Pilot@@ Projekt]. Encoder and attention components are not shown.
1. Deletion Classifier, which predicts for each token position whether they should be "kept" or "deleted",
2. **Placeholder Classifier**, which predicts the number of tokens to be inserted between every two consecutive tokens and then inserts the corresponding number of placeholder [PLH] tokens,
3. Token Classifier, which predicts for each [PLH] token an actual target token.
Each prediction is conditioned on the source text and the current target text. The same Transformer decoder block is shared among the three classifiers. Decoding stops when the current target text does not change, or a maximum number of refinement iterations has been reached.
The LevT model is trained using sequence-level knowledge distillation (Kim and Rush, 2016) from a Transformer teacher whose beam search output is used as ground truth during training. We refer the readers to (Gu et al., 2019) for a detailed description of the LevT model and training routine.
4 Incorporating Lexical Constraints
For sequence generation, the LevT decoder typically starts the first iteration of the decoding process with only the sentence boundary tokens  $\mathbf{y}^0 = < s > < / s>$ . To incorporate lexical constraints, we populate the  $\mathbf{y}^0$  sequence before the first deletion
operation with the target constraints, as shown in Figure 1. The initial target sequence will pass through the deletion, placeholder, and insertion classifiers sequentially, and the modified sequence will be refined for several iterations. The decoding steps are explained in detail below.
Constraint Insertion More formally, given a list of  $m$  target constraints  $C_1,C_2,\ldots ,C_m$  , where each constraint  $C_i$  is possibly a multi-token phrase  $C_i =$ $w_{1}^{i},w_{2}^{i},\dots,w_{|C_{i}|}^{i}$  , we insert the constraints into the decoding sequence before the deletion operation to form  $\mathbf{y}^0 = <  s > C_1C_2\dots C_n <   / s > .$
Deletion Operation Next,  $\mathbf{y}^0$  passes through the deletion classifier to decide which  $w_{j}^{i}$  token to remove. If the deletion operation is allowed on the constraint tokens, the presence of each constraint in the final output is not guaranteed, especially when the supplied constraints are out of context for the decoder. To mitigate this problem, we optionally disallow the deletion operation on the constraint tokens by introducing a constraint mask to indicate the positions of constraint tokens in the sequence. We forcefully set the deletion classifier prediction for all positions in this mask to "keep". The positions in this mask are re-computed accordingly after each deletion and insertion operation.
Insertion Operation Finally, the  $\mathbf{y}^0$  passes through the placeholder classifier to predict the number of tokens to be inserted and generate the corresponding number of [PLH] tokens and the token classifier assigns an actual target token for every [PLH] token. Each constraint may contain multiple tokens, and the [PLH] tokens may be inserted between the tokens from the same constraint. To prevent this from happening and to keep each constraint intact, we optionally prohibit inserting [PLH] within a multi-token constraint by constraining 0 to the number of such placeholders.
In Figure 1, our constraint insertion is executed at the first pass, and subsequent iterations start from deletion (indicated by a loop in the figure). We note that this step happens only at inference; during training, the original LevT training routine is carried out without the constraint insertion.
We extend the FAIRSEQ² (Ott et al., 2019) implementation of the original LevT architecture to per
Term%	BLEU	Speed (sent/sec)
Full	Constr.
Baseline LevT	80.23	26.49	29.86	263.11
+ Constr. Ins.	94.43	26.50	29.93	260.19
+ No Del.	99.62	26.59	30.43	260.61
+ No Ins.	100.00	26.60	30.49	254.64
Table 1: Results of LevT with lexical constraints on WMT14 En-De task
form lexically-constrained decoding. All Transformer blocks in our LevT model follow the base configuration that contains 6 layers with 8 attention heads each, with a model size  $d_{\mathrm{model}} = 512$  and feed-forward layer size  $d_{\mathrm{ff}} = 2048$ ; the source and target embeddings share the same vocabulary. The LevT model is trained using knowledge distillation routine using Transformer base output released by Gu et al. (2019). We leave more experimental details in the Appendix.
5.1 Data and evaluation settings
We evaluate our approach on the WMT'14 English-German (En-De) news translation task (Bojar et al., 2014) with En-De bilingual dictionary entries extracted from Wiktionary $^3$  following Dinu et al. (2019), by matching the source and target phrases of the dictionary entries in the source and target sentences, respectively.
We also evaluate our approach on two En-De test sets released by Dinu et al. (2019) to compare our approach against previous work on applying lexical constraints in NMT (Post and Vilar, 2018; Dinu et al., 2019). The two test sets are subsets of WMT'17 En-De test set (Bojar et al., 2017) extracted using Wiktionary and the Interactive Terminology for Europe (IATE) terminology database, respectively. Both the WMT'14 and WMT'17 En-De datasets are tokenized using the Moses tokenization scripts and segmented into sub-word units using byte-pair encoding (Sennrich et al., 2016).
We evaluate the systems using BLEU scores (Papineni et al., 2002) and term usage rate (Term%), which is defined as the number of constraints generated in the output divided by the total number of the given constraints.
Table 1 shows the result of (i) the baseline LevT model, (ii) with the constraint insertion operation  $(+Constr. Ins.)$ , (iii) with the constraint insertion
$^{2}$ https://github.com/pytorch/fairseq/commit/2d51e04
<sup>3</sup>https://dumps.wikimedia.org/enwiktionary/
<sup>4</sup>https://iate.europa.eu/
Source	“We don’t want to charge that,” she said.
Baseline LevT + Constr. Ins. + No Del. + No Ins. Reference	“Das都会 wir nicht in Rechnung stellen”, sagte sie.
“Das都会 wir nicht verlangen”, sagte sie.
“Das都会 wir nicht berechnen”, sagte sie.
“Wir können diese Summe nicht berechnen”, erklärte sie.
operation and forcefully disallowing deletion of the constraints  $(+NoDel.)$  and (iv) disallowing [PLH] insertion between tokens from the same constraint  $(+NoIns.)$ . Table 2 shows an example where prohibiting constraint deletion prevents catastrophic removal of the lexical constraint.
We report results on both the filtered test set for sentence pairs that contain at least one target constraint ("Constr.", 454 sentences) and the full test set ("Full", 3,003 sentences). The constraint insertion operation increases the term usage rate from about  $80\%$  to over  $94\%$ , and further disallowing deletion of the constraints achieves above  $99\%$  term usage. Prohibiting insertion between each constraint's tokens guarantees a  $100\%$  term usage. For sentences with lexical constraints, we observe a statistically significant improvement of 0.6 BLEU ( $p$ -value  $< 0.05$ ) based on bootstrap resampling (Koehn, 2004). On the full test set, the BLEU improves by 0.1. The small margin of improvement is because only  $1\%$  of the total reference tokens are constraint tokens. Unlike previous work that sacrificed decoding speed to enforce lexical constraints (e.g. Hasler et al., 2018; Post and Vilar, 2018), there is no significant difference in the number of sentences decoded per second between the unconstrained and the lexically constrained LevT models.
Table 3 presents the comparison to two previous approaches: constrained decoding with dynamic beam allocation (Post and Vilar, 2018) and data augmentation by replacing the source terms with target constraints during training (Dinu et al., 2019). We refer to them as POST18 and DINU19, respectively, in Table 3. We evaluate each approach on the WMT'17 En-De test set with constraint terms from Wiktionary and IATE dictionaries. Note that our baseline LevT model with Transformer blocks of 6 layers is superior to that of Dinu et al. (2019) who used a 2-layer configuration. Despite having a stronger baseline, we obtain higher absolute BLEU
Table 2: Example translations from the LevT with constraint insertion to enforce the translation of charge  $\rightarrow$  berechnen. When deletion is allowed (+ Constr. Ins.) the imposed constraint (berechnen) gets deleted during decoding. But when deletion is disallowed (+ No Del.) and unwanted insertion between constraint tokens is prohibited (+ No Ins.), it guarantees the presence of our desired term in the final translation. We show more examples in the Appendix.
Wiktionary	IATE
Term%	BLEU	Term%	BLEU
Previous work
Baseline Trans.	76.90	26.00	76.30	25.80
POST18	99.50	25.80	82.00	25.30
DINU19	93.40	26.30	94.50	26.00
This work
Baseline LevT	81.11	30.24	80.31	28.97
+ Constr. Ins.	93.44	30.82	93.81	29.73
+ No Del.	98.53	31.04	99.12	30.09
+ No Ins.	100.00	31.20	100.00	30.13
Table 3: Comparison to previous work. Baseline Transformer and Post18 results are from Dinu et al. (2019).
score improvements (0.96 and 1.16 BLEU on Wik-tionary and IATE, respectively) and achieved  $100\%$  term usage. We report additional experiments on WMT'16 Romanian-English news translation task (Bojar et al., 2016) in the Appendix.
To analyze if our approach inserts the constraints at correct positions, we compare it to a baseline approach of randomly inserting the constraint terms in the output of our baseline LevT model. Note that we only insert those constraints that are not already present in the output. Although this results in a  $100\%$  term usage, we observe that the BLEU score drops from 29.9 to 29.3 on the "Constr." WMT'14 test set, whereas our approach improves the BLEU score. The LevT model with our proposed constraint insertion seems to inherently have the ability to place the constraints at correct positions in the target sentence.
Although prohibiting constraint deletion improves term usage in the final translation and achieves higher BLEU scores, it limits the possibility of reordering when there is more than one constraint during inference. For the English-German test sets we evaluated on,  $97 - 99\%$  of the target constraints appear in the same order as the source terms. This issue may become more apparent in language pairs with more distinct syntactic differences
between the source and target languages. In practice, most of the entries in terminology databases (Wiktionary, IATE, etc.) are often nominal. Thus, the reordering of lexical constraints boils down to whether the source and target language share the same argument-predicate order.<sup>5</sup> We will explore potential strategies to reorder constraints dynamically in future work.
We proposed a non-autoregressive decoding approach to integrate lexical constraints for NMT. Our constraint insertion step is simple and we have empirically validated its effectiveness. The approach demonstrated control over constraint terms in target translations while being able to decode as fast as a baseline Levenshtein Transformer model, which achieves significantly higher decoding speed than traditional beam search. In addition to the terminological lexical constraints discussed in this work, future work can potentially modify insertion or selection operations to handle target translations of multiple forms; this can potentially disambiguate the morphological variants of the lexical constraints.
Ondrej Bojar, Christian Buck, Christian Federmann, Barry Haddow, Philipp Koehn, Johannes Leveling, Christof Monz, Pavel Pecina, Matt Post, Herve Saint-Amand, Radu Soricut, Lucia Specia, and Aleks Tamchyna. 2014. Findings of the 2014 workshop on statistical machine translation. In Proceedings of the Ninth Workshop on Statistical Machine Translation.
Ondrej Bojar, Rajen Chatterjee, Christian Federmann, Yvette Graham, Barry Haddow, Shujian Huang, Matthias Huck, Philipp Koehn, Qun Liu, Varvara Logacheva, Christof Monz, Matteo Negri, Matt Post, Raphael Rubino, Lucia Specia, and Marco Turchi. 2017. Findings of the 2017 conference on machine translation (WMT17). In Proceedings of the Second Conference on Machine Translation.
Ondrej Bojar, Rajen Chatterjee, Christian Federmann, Yvette Graham, Barry Haddow, Matthias Huck, Antonio Jimeno Yepes, Philipp Koehn, Varvara Logacheva, Christof Monz, Matteo Negri, Aurélie Nével, Mariana Neves, Martin Popel, Matt Post, Raphael Rubino, Carolina Scarton, Lucia Specia, Marco Turchi, Karin Verspoor, and Marcos
Zampieri. 2016. Findings of the 2016 conference on machine translation. In Proceedings of the First Conference on Machine Translation: Volume 2, Shared Task Papers.
Josep Maria Crego, Jungi Kim, Guillaume Klein, Anabel Rebollo, Kathy Yang, Jean Senellart, Egor Akhanov, Patrice Brunelle, Aurelien Coquard, Yongchao Deng, Satoshi Enoue, Chiyo Geiss, Joshua Johanson, Ardas Khalsa, Raoum Khiari, Byeongil Ko, Catherine Kobus, Jean Lorieux, Leidiana Martins, Dang-Chuan Nguyen, Alexandra Priori, Thomas Riccardi, Natalia Segal, Christophe Servan, Cyril Tiquet, Bo Wang, Jin Yang, Dakun Zhang, Jing Zhou, and Peter Zoldan. 2016. SYSTRAN's pure neural machine translation systems. arXiv preprint arXiv:1610.05540.
Georgiana Dinu, Prashant Mathur, Marcello Federico, and Yaser Al-Onaizan. 2019. Training neural machine translation to apply terminology constraints. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics.
Marjan Ghazvininejad, Omer Levy, Yinhan Liu, and Luke Zettlemoyer. 2019. Mask-predict: Parallel decoding of conditional masked language models. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP).
Jiatao Gu, James Bradbury, Caiming Xiong, Victor O. K. Li, and Richard Socher. 2018. Non-autoregressive neural machine translation. In 6th International Conference on Learning Representations, Conference Track Proceedings.
Jiatao Gu, Changhan Wang, and Junbo Zhao. 2019. Levenshtein transformer. In Advances in Neural Information Processing Systems 32.
Eva Hasler, Adrià de Gispert, Gonzalo Iglesias, and Bill Byrne. 2018. Neural machine translation decoding with terminology constraints. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers).
Chris Hokamp and Qun Liu. 2017. Lexically constrained decoding for sequence generation using grid beam search. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers).
J. Edward Hu, Huda Khayrallah, Ryan Culkin, Patrick Xia, Tongfei Chen, Matt Post, and Benjamin Van Durme. 2019. Improved lexically constrained decoding for translation and monolingual rewriting. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers).
5i.e., Subject (S), Verb (V), and Object (O), SOV, or VSO ordering. Our implementation will be made publicly available at https://github.com/raymondhs/constrained-levt.
Yoon Kim and Alexander M. Rush. 2016. Sequence-level knowledge distillation. In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing.
Philipp Koehn. 2004. Statistical significance tests for machine translation evaluation. In Proceedings of the 2004 Conference on Empirical Methods in Natural Language Processing.
Jason Lee, Elman Mansimov, and Kyunghyun Cho. 2018. Deterministic non-autoregressive neural sequence modeling by iterative refinement. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing.
Myle Ott, Sergey Edunov, Alexei Baevski, Angela Fan, Sam Gross, Nathan Ng, David Grangier, and Michael Auli. 2019. fairseq: A fast, extensible toolkit for sequence modeling. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics (Demonstrations).
Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. 2002. BLEU: a method for automatic evaluation of machine translation. In Proceedings of the 40th Annual Meeting of the Association for Computational Linguistics.
Matt Post and David Vilar. 2018. Fast lexically constrained decoding with dynamic beam allocation for neural machine translation. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers).
Rico Sennrich, Barry Haddow, and Alexandra Birch. 2016. Neural machine translation of rare words with subword units. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers).
Kai Song, Yue Zhang, Heng Yu, Weihua Luo, Kun Wang, and Min Zhang. 2019. Code-switching for enhancing NMT with pre-specified translation. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers).
Mitchell Stern, William Chan, Jamie Kiros, and Jakob Uszkoreit. 2019. Insertion transformer: Flexible sequence generation via insertion operations. In Proceedings of the 36th International Conference on Machine Learning.
Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems 30.