Title: INCORPORATING BERT INTO NEURAL MACHINE TRANSLATION

Abstract: The recently proposed BERT (Devlin et al., 2019) has shown great power on a variety of natural language understanding tasks, such as text classification, reading comprehension, etc. However, how to effectively apply BERT to neural machine translation (NMT) lacks enough exploration. While BERT is more commonly used as fine-tuning instead of contextual embedding for downstream language understanding tasks, in NMT, our preliminary exploration of using BERT as contextual embedding is better than using for fine-tuning. This motivates us to think how to better leverage BERT for NMT along this direction. We propose a new algorithm named BERT-fused model, in which we first use BERT to extract representations for an input sequence, and then the representations are fused with each layer of the encoder and decoder of the NMT model through attention mechanisms. We conduct experiments on supervised (including sentence-level and document-level translations), semi-supervised and unsupervised machine translation, and achieve state-of-the-art results on seven benchmark datasets. Our code is available at https://github.com/bert-nmt/bert-nmt.

1. INTRODUCTION:

Recently, pre-training techniques, like ELMo (Peters et al., 2018) , GPT/GPT-2 (Radford et al., 2018; 2019) , BERT (Devlin et al., 2019) , cross-lingual language model (briefly, XLM) (Lample & Conneau, 2019) , XLNet (Yang et al., 2019b) and RoBERTa (Liu et al., 2019) have attracted more and more attention in machine learning and natural language processing communities. The models are first pre-trained on large amount of unlabeled data to capture rich representations of the input, and then applied to the downstream tasks by either providing context-aware embeddings of an input sequence (Peters et al., 2018) , or initializing the parameters of the downstream model (Devlin et al., 2019) for fine-tuning. Such pre-training approaches lead to significant improvements on natural language understanding tasks. Among them, BERT is one of the most powerful techniques that inspires lots of variants like XLNet, XLM, RoBERTa and achieves state-of-the-art results for many language understanding tasks including reading comprehension, text classification, etc (Devlin et al., 2019) .

Neural Machine Translation (NMT) aims to translate an input sequence from a source language to a target language. An NMT model usually consists of an encoder to map an input sequence to hidden representations, and a decoder to decode hidden representations to generate a sentence in the target language. Given that BERT has achieved great success in language understanding tasks, a question worthy studying is how to incorporate BERT to improve NMT. Due to the computation resource limitation, training a BERT model from scratch is unaffordable for many researchers. Thus, we focus on the setting of leveraging a pre-trained BERT model (instead of training a BERT model from scratch) for NMT.

Given that there is limited work leveraging BERT for NMT, our first attempt is to try two previous strategies: (1) using BERT to initialize downstream models and then fine-tuning the models, and (2) using BERT as context-aware embeddings for downstream models. For the first strategy, following Devlin et al. (2019) , we initialize the encoder of an NMT model with a pre-trained BERT model, and then finetune the NMT model on the downstream datasets. Unfortunately, we did not observe significant improvement. Using a pre-trained XLM (Lample & Conneau, 2019) model, a variant of BERT for machine translation, to warm up an NMT model is another choice. XLM has been verified to be helpful for WMT'16 Romanian-to-English translation. But when applied to a language domain beyond the corpus for training XLM (such as IWSLT dataset (Cettolo et al., 2014) , which is about spoken languages) or when large bilingual data is available for downstream tasks, no significant improvement is observed neither. For the second strategy, following the practice of (Peters et al., 2018) , we use BERT to provide context-aware embeddings for the NMT model. We find that this strategy outperforms the first one (please refer to Section 3 for more details). This motivates us to go along this direction and design more effective algorithms.

We propose a new algorithm, BERT-fused model, in which we exploit the representation from BERT by feeding it into all layers rather than served as input embeddings only. We use the attention mechanism to adaptively control how each layer interacts with the representations, and deal with the case that BERT module and NMT module might use different word segmentation rules, resulting in different sequence (i.e., representation) lengths. Compared to standard NMT, in addition to BERT, there are two extra attention modules, the BERT-encoder attention and BERT-decoder attention. An input sequence is first transformed into representations processed by BERT. Then, by the BERTencoder attention module, each NMT encoder layer interacts with the representations obtained from BERT and eventually outputs fused representations leveraging both BERT and the NMT encoder. The decoder works similarly and fuses BERT representations and NMT encoder representations.

We conduct 14 experiments on various NMT tasks to verify our approach, including supervised, semi-supervised and unsupervised settings. For supervised NMT, we work on five tasks of IWSLT datasets and two WMT datasets. Specifically, we achieve 36.11 BLEU score on IWSLT'14 Germanto-English translation, setting a new record on this task. We also work on two document-level translations of IWSLT, and further boost the BLEU score of German-to-English translation to 36.69. On WMT'14 datasets, we achieve 30.75 BLEU score on English-to-German translation and 43.78 on English-to-French translation, significantly better over the baselines. For semi-supervised NMT, we boost BLEU scores of WMT'16 Romanian-to-English translation with back translation (Sennrich et al., 2016b) , a classic semi-supervised algorithm, from 37.73 to 39.10, achieving the best result on this task. Finally, we verify our algorithm on unsupervised English↔French and unsupervised English↔Romanian translations and also achieve state-of-the-art results.

2. BACKGROUND AND RELATED WORK:

We briefly introduce the background of NMT and review current pre-training techniques.

NMT aims to translate an input sentence from the source language to the target one. An NMT model usually consists of an encoder, a decoder and an attention module. The encoder maps the input sequence to hidden representations and the decoder maps the hidden representations to the target sequence. The attention module is first introduced by Bahdanau et al. (2015) , which is used to better align source words and target words. The encoder and decoder can be specialized as LSTM (Hochreiter & Schmidhuber, 1997; Sutskever et al., 2014; Wu et al., 2016) , CNN (Gehring et al., 2017) and Transformer (Vaswani et al., 2017) . A Transformer layer consists of three sublayers, a self-attention layer that processes sequential data taking the context of each timestep into consideration, an optional encoder-decoder attention layer that bridges the input sequence and target sequence which exists in decoder only, and a feed-forward layer for non-linear transformation. Transformer achieves the state-of-the-art results for NMT (Barrault et al., 2019) . In this work, we will use Transformer as the basic architecture of our model.

Pre-training has a long history in machine learning and natural language processing (Erhan et al., 2009; 2010) . Mikolov et al. (2013) and Pennington et al. (2014) proposed to use distributional representations (i.e., word embeddings) for individual words. Dai & Le (2015) proposed to train a language model or an auto-encoder with unlabeled data and then leveraged the obtained model to finetune downstream tasks. Pre-training has attracted more and more attention in recent years and achieved great improvements when the data scale becomes large and deep neural networks are employed. ELMo was proposed in Peters et al. (2018) based on bidirectional LSTMs and its pre-trained models are fed into downstream tasks as context-aware inputs. In GPT (Radford et al., 2018) , a Transformer based language model is pre-trained on unlabeled dataset and then finetuned on downstream tasks. BERT (Devlin et al., 2019) is one of the widely adopted pre-training approach for model initialization. The architecture of BERT is the encoder of Transformer (Vaswani et al., 2017) . Two kinds of objective functions are used in BERT training: (1) Masked language modeling (MLM), where 15% words in a sentence are masked and BERT is trained to predict them with their surrounding words. (2) Next sentence prediction (NSP): Another task of pre-training BERT is to predict whether two input sequences are adjacent. For this purpose, the training corpus consists of tuples ([cls] , input 1, [sep], input 2, [sep]), with learnable special tokens [cls] to classify whether input 1 and input 2 are adjacent and [sep] to segment two sentences, and with probability 50%, the second input is replaced with a random input. Variants of BERT have been proposed: In XLM (Lample & Conneau, 2019) , the model is pre-trained based on multiple languages and NSP task is removed; in RoBERTa (Liu et al., 2019) , more unlabeled data is leveraged without NSP task neither; in XLNet (Yang et al., 2019b) , a permutation based modeling is introduced.

3. A PRELIMINARY EXPLORATION:

While a few pieces of work (Lample & Conneau, 2019; Song et al., 2019) design specific pretraining methods for NMT, they are time and resource consuming given that they need to pre-train large models from scratch using large-scale data, and even one model for each language pair. In this work, we focus on the setting of using a pre-trained BERT model. Detailed model download links can be found in Appendix D.

Considering that pre-trained models have been utilized in two different ways for other natural language tasks, it is straightforward to try them for NMT. Following previous practice, we make the following attempts.

(I) Use pre-trained models to initialize the NMT model. There are different implementations for this approach. (1) Following (Devlin et al., 2019) , we initialize the encoder of an NMT model with a pretrained BERT. (2) Following (Lample & Conneau, 2019) , we initialize the encoder and/or decoder of an NMT model with XLM.

(II) Use pre-trained models as inputs to the NMT model. Inspired from (Peters et al., 2018) , we feed the outputs of the last layer of BERT to an NMT model as its inputs.

We conduct experiments on the IWSLT'14 English→German translation, a widely adopted dataset for machine translation consisting of 160k labeled sentence pairs. We choose Transformer (Vaswani et al., 2017) as the basic model architecture with transformer iwslt de en configuration (a six-layer model with 36.7M parameters). The translation quality is evaluated by BLEU (Papineni et al., 2002) score; the larger, the better. Both BERT base and XLM models are pre-trained and we get them from the Web. More details about the experimental settings are included in Appendix A.2. The results are shown in Table 1 . We have several observations: (1) Using BERT to initialize the encoder of NMT can only achieve 27.14 BLEU score, which is even worse than standard Transformer without using BERT. That is, simply using BERT to warm up an NMT model is not a good choice.

(2) Using XLM to initialize the encoder or decoder respectively, we get 28.22 or 26.13 BLEU score, which does not outperform the baseline. If both modules are initialized with XLM, the BLEU score is boosted to 28.99, slightly outperforming the baseline. Although XLM achieved great success on WMT'16 Romanian-to-English, we get limited improvement here. Our conjecture is that the XLM model is pre-trained on news data, which is out-of-domain for IWSLT dataset mainly about spoken languages and thus, leading to limited improvement. (3) When using the output of BERT as context-aware embeddings of the encoder, we achieve 29.67 BLEU, much better than using pretrained models for initialization. This shows that leveraging BERT as a feature provider is more effective in NMT. This motivates us to take one step further and study how to fully exploit such features provided by pre-trained BERT models.

4. ALGORITHM:

In this section, we first define the necessary notations, then introduce our proposed BERT-fused model and finally provide discussions with existing works.

Notations Let X and Y denote the source language domain and target language domain respectively, which are the collections of sentences with the corresponding languages. For any sentence x ∈ X and y ∈ Y, let l x and l y denote the number of units (e.g., words or sub-words) in x and y. The i-th unit in x/y is denoted as x i /y i . Denote the encoder, decoder and BERT as Enc, Dec and BERT respectively. For ease of reference, we call the encoder and decoder in our work as the NMT module. W.l.o.g., we assume both the encoder and decoder consists of L layers. Let attn(q, K, V ) denote the attention layer, where q, K and V indicate query, key and value respectively (Vaswani et al., 2017) . We use the same feed-forward layer as that used in (Vaswani et al., 2017) and denote it as FFN. Mathematical formulations of the above layers are left at Appendix E.

4.1. BERT-FUSED MODEL:

An illustration of our algorithm is shown in Figure 1 . Any input x ∈ X is progressively processed by the BERT, encoder and decoder. Step-1: Given any input x ∈ X , BERT first encodes it into representation H B = BERT(x). H B is the output of the last layer in BERT. The h B,i ∈ H B is the representation of the i-th wordpiece in x.

BERT-Enc Attention:

Step-2: Let H l E denote the hidden representation of l-th layer in the encoder, and let H 0 E denote word embedding of sequence x. Denote the i-th element in H l E as h l i for any i ∈ [l x ]. In the l-th

EQUATION

where attn S and attn B are attention models (see Eqn.( 6)) with different parameters. Then each hl i is further processed by FFN(•) defined in Eqn.( 7) and we get the output of the l-th layer:

H l E = (FFN( hl 1 ), • • • , FFN( hl lx )

). The encoder will eventually output H L E from the last layer.

Step-3: Let S l <t denote the hidden state of l-th layer in the decoder preceding time step t, i.e., S l <t = (s l 1 , • • • , s l t-1 ). Note s 0 1 is a special token indicating the start of a sequence, and s 0 t is the embedding of the predicted word at time-step t -1. At the l-th layer, we have

ŝl t = attn S (s l-1 t , S l-1 <t+1 , S l-1 <t+1 ); sl t = 1 2 attn B (ŝ l t , H B , H B ) + attn E (ŝ l t , H L E , H L E ) , s l t = FFN(s l t ).

(2)

The attn S , attn B and attn E represent self-attention model, BERT-decoder attention model and encoder-decoder attention model respectively. Eqn.( 2) iterates over layers and we can eventually obtain s L t . Finally s L t is mapped via a linear transformation and softmax to get the t-th predicted word ŷt . The decoding process continues until meeting the end-of-sentence token.

In our framework, the output of BERT serves as an external sequence representation, and we use an attention model to incorporate it into the NMT model. This is a general way to leverage the pre-trained model regardless of the tokenization way.

4.2. DROP-NET TRICK:

Inspired by dropout (Srivastava et al., 2014) and drop-path (Larsson et al., 2017) , which can regularize the network training, we propose a drop-net trick to ensure that the features output by BERT and the conventional encoder are fully utilized. The drop-net will effect Eqn.(1) and Eqn.(2). Denote the drop-net rate as p net ∈ [0, 1]. At each training iteration, for any layer l, we uniformly sample a random variable U l from [0, 1], then all the hl i in Eqn.

(1) are calculated in the following way:

EQUATION

where I(•) is the indicator function. For any layer, with probability p net /2, either the BERT-encoder attention or self-attention is used only; w.p. (1 -p net ), both the two attention models are used. For example, at a specific iteration, the first layer might uses attn S only while the second layer uses attn B only. During inference time, the expected output of each attention model is used, which is

E U ∼uniform[0,1] ( hl i,drop-net ).

The expectation is exactly Eqn.(1). Similarly, for training of the decoder, with the drop-net trick, we have

EQUATION

For inference, it is calculated in the same way as Eqn.

(2). Using this technique can prevent network from overfitting (see the second part of Section 6 for more details).

4.3. DISCUSSION:

Comparison with ELMo As introduced in Section 2, ELMo (Peters et al., 2018) provides a contextaware embeddings for the encoder in order to capture richer information of the input sequence. Our approach is a more effective way of leveraging the features from the pre-trained model: (1) The output features of the pre-trained model are fused in all layers of the NMT module, ensuring the well-pre-trained features are fully exploited;

(2) We use the attention model to bridge the NMT module and the pre-trained features of BERT, in which the NMT module can adaptively determine how to leverage the features from BERT.

Limitations We are aware that our approach has several limitations. (1) Additional storage cost: our approach leverages a BERT model, which results in additional storage cost. However, considering the BLEU improvement and the fact that we do not need additional training of BERT, we believe that the additional storage is acceptable. (2) Additional inference time: We use BERT to encode the input sequence, which takes about 45% additional time (see Appendix C for details). We will leave the improvement of the above two limitations as future work.

5. APPLICATION TO SUPERVISED NMT AND SEMI-SUPERVISED NMT:

We first verify our BERT-fused model on the supervised setting, including low-resource and richresource scenarios. Then we conduct experiments on document-level translation to verify our approach. Finally, we combine BERT-fused model with back translation (Sennrich et al., 2016b) to verify the effectiveness of our method on semi-supervised NMT.

5.1. SETTINGS:

Dataset For the low-resource scenario, we choose IWSLT'14 English↔German (En↔De), English→Spanish (En→Es), IWSLT'17 English→French (En→Fr) and English→Chinese (En→Zh) translation. There are 160k, 183k, 236k, 235k bilingual sentence pairs for En↔De, En→Es, En→Fr and En→Zh tasks. Following the common practice (Edunov et al., 2018) , for En↔De, we lowercase all words. All sentences are preprocessed by BPE (Sennrich et al., 2016c Training Strategy We first train an NMT model until convergence, then initialize the encoder and decoder of the BERT-fused model with the obtained model. The BERT-encoder attention and BERTdecoder attention are randomly initialized. Experiments on IWSLT and WMT tasks are conducted on 1 and 8 M40 GPUs respectively. The batchsize is 4k tokens per GPU. Following (Ott et al., 2018) , for WMT tasks, we accumulate the gradient for 16 iterations and then update to simulate a 128-GPU environment. It takes 1, 8 and 14 days to obtain the pre-trained NMT models, and additional 1, 7 and 10 days to finish the whole training process. The optimization algorithm is Adam (Kingma & Ba, 2014) with initial learning rate 0.0005 and inverse sqrt learning rate scheduler (Vaswani et al., 2017) . For WMT'14 En→De, we use beam search with width 4 and length penalty 0.6 for inference following (Vaswani et al., 2017) . For other tasks, we use width 5 and length penalty 1.0.

Evaluation We use multi-bleu.perl to evaluate IWSLT'14 En↔De and WMT translation tasks for fair comparison with previous work. For the remaining tasks, we use a more advance implementation of BLEU score, sacreBLEU for evaluation. Script urls are in Appendix A.1. The results of IWSLT translation tasks are reported in Table 2. We implemented standard Transformer as baseline.

5.2. RESULTS:

Our proposed BERT-fused model can improve the BLEU scores of the five tasks by 1.88, 1.47, 2.4, 1.9 and 2.8 points respectively, demonstrating the effectiveness of our method. The consistent improvements on various tasks shows that our method works well for low-resource translations. We achieved state-of-the-art results on IWSLT'14 De→En translation, a widely investigated baseline in ma-chine translation. The comparison with previous methods are shown in Appendix B.4 due to space limitation.

The results of WMT'14 En→De and En→Fr are shown in Table 3 . Our reproduced Transformer matches the results reported in Ott et al. (2018) , and we can see that our BERT-fused model can improve these two numbers to 30.75 and 43.78, achieving 1.63 and 0.82 points improvement. Our approach also outperforms the well-designed model DynamicConv (Wu et al., 2019) and a model obtained through neural architecture search (So et al., 2019) . BERT is able to capture the relation between two sentences, since the next sentence prediction (NSP) task is to predict whether two sentences are adjacent. We can leverage this property to improve translation with document-level contextual information (Miculicich et al., 2018) , which is briefly denoted as document-level translation. The inputs are a couple of sentences extracted from a paragraph/document,

x d 1 , x d 2 , • • • , x d T ,

where the T x's are contextually correlated. We want to translate them into target language by considering the contextual information.

Algorithm In our implementation, to translate a sentence x to target domain, we leverage the contextual information by taking both x and its preceding sentence x prev as inputs. x is fed into Enc, which is the same as sentence-level translation. et al. (2018) , where multiple preceding sentences in a document are leveraged using a hierarchical attention network.

Results:

The results are shown in Table 4 . We can see that introducing contextual information from an additional encoder can boost the sentence-level baselines, but the improvement is limited (0.33 for En→De and 0.31 for De→En). For Miculicich et al. (2018) , the best results we obtain are 27.94 and 33.97 respectively, which are worse than the sentence-level baselines. Combining BERT-fused model and document-level information, we can eventually achieve 31.02 for En→De and 36.69 for De→En. We perform significant test1 between sentence-level and document-level translation. Our document-level BERT-fused model significantly outperforms sentence-level baseline with p-value less than 0.01. This shows that our approach not only works for sentence-level translation, but can also be generalized to document-level translation.

Published as a conference paper at ICLR 2020

5.4. APPLICATION TO SEMI-SUPERVISED NMT:

We work on WMT'16 Romanian→English (Ro→En) translation to verify whether our approach can still make improvement over back translation (Sennrich et al., 2016b) , the standard and powerful semi-supervised way to leverage monolingual data in NMT.

The number of bilingual sentence pairs for Ro→En is 0.6M . Sennrich et al. (2016a) provided 2M back translated data2 . We use newsdev2016 as validation set and newstest2016 as test set. Sentences were encoded using BPE with a shared source-target vocabulary of about 32k tokens. We use transformer big configuration. Considering there is no Romanian BERT, we use the cased multilingual BERT (please refer to Appendix D) to encode inputs. The drop-net rate p net is set as 1.0. The translation quality is evaluated by multi-bleu.perl. The results are shown in Table 5 . The Transformer baseline achieves 33.12 BLEU score. With back-translation, the performance is boosted to 37.73. We use the model obtained with back-translation to initialize BERT-fused model, and eventually reach 39.10 BLEU. Such a score surpasses the previous best result 38.5 achieved by XLM (Lample & Conneau, 2019) and sets a new record. This demonstrates that our proposed approach is effective and can still achieve improvement over strong baselines.

6. ABLATION STUDY:

We conduct two groups of ablation studies on IWSLT'14 En→De translation to better understand our model. 

Study for training strategy and network architecture:

We conduct ablation study to investigate the performance of each component of our model and training strategy. Results are reported in Table 6 :

(1) We randomly initialize the NMT module (i.e., encoder and decoder) of BERT-fused model instead of using a warm-start one as introduced in the training strategy of Section 5.1. In this way, we can only achieve 27.03 BLEU score, which cannot catch up with the baseline. We also jointly train BERT model with the NMT module. Although it can also boost the baseline from 28.57 to 28.87, it is not as good as fixing the BERT part, whose BLEU is 30.45.

(2) We feed the output of BERT into all layers of the encoder without attention models. That is, the Eqn.( 1) is revised to

hl i = 1 2 attn S (h l-1 i , H l-1 E , H l-1 E ) + W l B h l-1 i )

, where W l B is learnable. In this case, the encoder and BERT have to share the same vocabulary. The BLEU score is 29.61, which is better than the standard Transformer but slightly worse than leveraging the output of BERT as embedding. This shows that the output of BERT should not be fused into each layer directly, and using the attention model to bridge the relation is better than using simple transformation. More results on different languages are included in Appendix B.3. To illustrate the effectiveness of our method, we choose another two kinds of ways to encode the input sequence rather than using BERT:

(1) Using a fixed and randomly initialized embedding; (2) Using the encoder from another NMT model. Their BLEU scores are 28.91 and 28.99 respectively, indicating that the BERT pre-trained on large amount of unlabeled data can provide more helpful features to NMT.

(3) To verify where the output of BERT should be connected to, we remove the BERT-encoder attention (i.e., attn B in Eqn.( 1)) and the BERT-decoder attention (i.e,, attn B in Eqn.(2)) respectively. Correspondingly, the BLEU score drops from 30.45 to 29.87 and 29.90. This indicates that the output of BERT should be leveraged by both encoder and decoder to achieve better performances. At last, considering that there are two stacked encoders in our model, we also choose ensemble models and deeper NMT models as baselines. Our approach outperforms the above baselines. The results are left in Appendix B.2 due to space limitation.

Study on drop-net:

To investigate the effect of drop-net, we conduct experiments on IWSLT'14 En→De dataset with different drop-net probability, p net ∈ {0, 0.2, 0.4, 0.6, 0.8, 1.0}. The results are shown in Figure 2 . As can been seen, although larger p net leads to larger training loss, it leads to smaller validation loss and so better BLUE scores. This shows that the drop-net trick can indeed improve the generalization ability of our model. We fix p net = 1.0 in other experiments unless specially specified. 

7. APPLICATION TO UNSUPERVISED NMT:

We work on unsupervised En↔Fr and En↔Ro translation. The data processing, architecture selection and training strategy is the same as Lample & Conneau (2019) .

Settings For En↔Fr, we use 190M monolingual English sentences and 62M monolingual French sentences from WMT News Crawl datasets, which is the same as that used in (Song et al., 2019) . 3For unsupervised En↔Ro translation, we use 50M English sentences from News Crawl (sampled from the data for En→Fr) and collect 2.9M sentences for Romanian by concatenating News Crawl data sets and WMT'16 Romanian monolingual data following Lample et al. (2018) . The data is preprocessed in the same way as Lample & Conneau (2019) .

We use the same model configuration as Lample & Conneau (2019) , with details in Appendix A.3. The BERT is the pre-trained XLM model (see Appendix D). We first train an unsupervised NMT model following Lample & Conneau (2019) until convergence. Then we initialize our BERT-fused model with the obtained model and continue training. We train models on 8 M40 GPUs, and the batchsize is 2000 tokens per GPU. We use the same optimization hyper-parameters as that described in Lample & Conneau (2019) . 

8. CONCLUSION AND FUTURE WORK:

In this work, we propose an effective approach, BERT-fused model, to combine BERT and NMT, where the BERT is leveraged by the encoder and decoder through attention models. Experiments on supervised NMT (including sentence-level and document-level translations), semi-supervised NMT and unsupervised NMT demonstrate the effectiveness of our method.

For future work, there are many interesting directions. First, we will study how to speed up inference time. Second, we can apply such an algorithm to more applications, like questioning and answering. Third, how to compress BERT-fused model into a light version is another topic. There are some contemporary works leveraging knowledge distillation to combine pre-trained models with NMT (Yang et al., 2019a; Chen et al., 2019) , which is a direction to explore.

B.2 MORE ABLATION STUDY:

Part I: A different way to deal with multiple attention models Junczys-Dowmunt & Grundkiewicz (2018) proposed a new way to handle multiple attention models. Instead of using Eqn.(2), the input is processed by self-attention, encoder-decoder attention and BERT-decoder attention sequentially. Formally,

EQUATION

The BLEU score is 29.35 for this setting, not as good as our proposed method.

Part II: More results on IWSLT'14 En→De translation

Since our BERT-fused model contains two stacked encoders, we carry out two groups of additional baselines:

(1) Considering that stacking the BERT and encoder can be seen as a deeper model, we also train another two NMT models with deeper encoders, one with 18 layers (since BERT base consists of 12 layers) and the other with 12 layers (which achieved best validation performance ranging from 6 to 18 layers).

(2) We also compare the results of our approach with ensemble methods. To get an M -model ensemble, we independently train M models with different random seeds (M ∈ Z + ). We ensemble both standard Transformers and our BERT-fused models, which are denoted as M -model ensemble (standard) and M -model ensemble (BERT-fused) respectively. Please note that when we aggregate multiple BERT-fused models, we only need to store one replica of the BERT model because the BERT part is not optimized. The results are shown in Table 8 . We have the following observations:

1. Adding more layers can indeed boost the baseline, but still not as good as BERT-fused model. According to our experiments, when increasing the number of layers to 12, we achieve the best BLEU score, 29.27.

2. We also compare our results to ensemble methods. Indeed, ensemble significantly boost the baseline by more than one point. However, even if using ensemble of four models, the BLEU score is still lower than our , which shows the effectiveness of our method.

We want to point out that our method is intrinsically different from ensemble. Ensemble approaches usually refer to "independently" train several different models for the same task, and then aggregate B.5 COMPARISON WITH BACK TRANSLATION When using unlabeled data to boost machine learning systems, one of the most notable approaches is back translation (briefly, BT) (Sennrich et al., 2016b) : We first train a reversed translation model, use the obtained model to translate the unlabeled data in the target domain back to source domain, obtain a synthetic dataset where the source data is back-translated and finally train the forward model on the augmented dataset.

Our method has two main differences with BT method.

1. In BT, the monolingual data from the target side is leveraged. In our proposed approach, we use a BERT of the source language, which indirectly leverages the monolingual data from the source side. In this way, our approach and BT are complementary to each other. In Section 5.4, we have already verified that our method can further improve the results of standard BT on Romanian-to-English translation.

2. To use BT, we have to train a reversed translation model and then back translate the monolingual data, which is time-cost due to the decoding process. In BERT-fused model, we only need to download a pre-trained BERT model, incorporate it into our model and continue training. Besides, the BERT module is fixed during training.

On IWSLT'14, we also implement BT on wikipedia data, which is a subset of the corpus of training BERT. The model used for back translation are standard Transformer baselines introduced in Section 5, whose BLEU scores are 28.57 and 34.64 respectively. We back translate 1M, 2M, 5M, 15M and 25M randomly selected German sentences.

The results are reported in Table 12 . The rows started with BT(•) represent the results of BT, and the numbers in the brackets are the number of sentences for back translation. IWSLT dataset is a collection of spoken language, and the bilingual training corpus is small (160k).

In Wikipedia, the sentences are relatively formal compared to the spoken language, which is outof-domain of spoken languages. We can see that when using 1M or 2M monolingual data for BT, the BLEU scores can indeed improve from 28.57 to 29.42/29.76. However, simply adding more wikipedia data for BT does not result in more improvement. There is even a slight drop when adding more than 15M monolingual sentences. However, our BERT-fused model can achieve better performances than BT with wikipedia data. 

C COMPARISON OF INFERENCE TIME:



:

https://github.com/moses-smt/mosesdecoder/blob/master/scripts/ analysis/bootstrap-hypothesis-difference-significance.pl

Data at http://data.statmt.org/rsennrich/wmt16_backtranslations/ro-en/.

Data source: https://modelrelease.blob.core.windows.net/mass/en-fr.tar.gz.

https://github.com/moses-smt/mosesdecoder/blob/master/scripts/generic/ multi-bleu.perl

https://github.com/mjpost/sacreBLEU.

https://github.com/huggingface/pytorch-transformers

Figures and Tables:

Figure 1: The architecture of BERT-fused model. The left and right figures represent the BERT, encoder and decoder respectively. Dash lines denote residual connections. H B (red part) and H L E

For the input of BERT, it is the concatenation of two sequences: ([cls], x prev , [sep], x, [sep]), where both [cls] and [sep] are special tokens of BERT.Setting We use IWSLT'14 En↔De dataset as introduced in Section 5.1. The data is a collection of TED talks, where each talk consists of several sequences. We can extract the adjacent sentences for training, validation and test sets. The training strategy, hyperparameter selection and evaluation metric are the same for sentence-level translation.

Figure 2: Training/validation curves with different p net 's.

Preliminary explorations on IWSLT'14 English→German translation.

Table content: <table><tr><td>Algorithm</td><td>BLEU score</td></tr><tr><td>Standard Transformer</td><td>28.57</td></tr><tr><td>Use BERT to initialize the encoder of NMT</td><td>27.14</td></tr><tr><td>Use XLM to initialize the encoder of NMT</td><td>28.22</td></tr><tr><td>Use XLM to initialize the decoder of NMT</td><td>26.13</td></tr><tr><td>Use XLM to initialize both the encoder and decoder of NMT</td><td>28.99</td></tr><tr><td>Leveraging the output of BERT as embeddings</td><td>29.67</td></tr></table>

BLEU of all IWSLT tasks.

Table content: <table><tr><td/><td colspan="2">Transformer BERT-fused</td></tr><tr><td>En→De</td><td>28.57</td><td>30.45</td></tr><tr><td>De→En</td><td>34.64</td><td>36.11</td></tr><tr><td>En→Es</td><td>39.0</td><td>41.4</td></tr><tr><td>En→Zh</td><td>26.3</td><td>28.2</td></tr><tr><td>En→Fr</td><td>35.9</td><td>38.7</td></tr></table>



Table content: <table><tr><td colspan="2">: BLEU scores of WMT'14 translation.</td><td/></tr><tr><td>Algorithm</td><td colspan="2">En→De En→Fr</td></tr><tr><td>DynamicConv (Wu et al., 2019)</td><td>29.7</td><td>43.2</td></tr><tr><td>Evolved Transformer (So et al., 2019)</td><td>29.8</td><td>41.3</td></tr><tr><td>Transformer + Large Batch (Ott et al., 2018)</td><td>29.3</td><td>43.0</td></tr><tr><td>Our Reproduced Transformer</td><td>29.12</td><td>42.96</td></tr><tr><td>Our BERT-fused model</td><td>30.75</td><td>43.78</td></tr><tr><td colspan="3">5.3 TRANSLATION WITH DOCUMENT-LEVEL CONTEXTUAL INFORMATION</td></tr></table>

BLEU of document-level translation.

Table content: <table><tr><td/><td colspan="2">En→De De→En</td></tr><tr><td>Sentence-level</td><td>28.57</td><td>34.64</td></tr><tr><td>Our Document-level</td><td>28.90</td><td>34.95</td></tr><tr><td>Miculicich et al. (2018)</td><td>27.94</td><td>33.97</td></tr><tr><td>Sentence-level + BERT</td><td>30.45</td><td>36.11</td></tr><tr><td>Document-level + BERT</td><td>31.02</td><td>36.69</td></tr></table>

BLEU scores of WMT'16 Ro→En.

Table content: <table><tr><td>Methods</td><td>BLEU</td></tr><tr><td>Sennrich et al. (2016a)</td><td>33.9</td></tr><tr><td>XLM (Lample &amp; Conneau, 2019)</td><td>38.5</td></tr><tr><td>Standard Transformer</td><td>33.12</td></tr><tr><td>+ back translation</td><td>37.73</td></tr><tr><td>+ BERT-fused model</td><td>39.10</td></tr></table>

Ablation study on IWSLT'14 En→De.

Table content: <table><tr><td>Standard Transformer</td><td>28.57</td></tr><tr><td>BERT-fused model</td><td>30.45</td></tr><tr><td>Randomly initialize encoder/decoder of BERT-fused model</td><td>27.03</td></tr><tr><td colspan="2">Jointly tune BERT and encoder/decoder of BERT-fused model 28.87</td></tr><tr><td>Feed BERT feature into all layers without attention</td><td>29.61</td></tr><tr><td>Replace BERT output with random vectors</td><td>28.91</td></tr><tr><td colspan="2">Replace BERT with the encoder of another Transformer model 28.99</td></tr><tr><td>Remove BERT-encoder attention</td><td>29.87</td></tr><tr><td>Remove BERT-decoder attention</td><td>29.90</td></tr></table>

BLEU scores of unsupervised NMT.ResultsThe results of unsupervised NMT are shown in Table7. With our proposed BERT-fused model, we can achieve 38.27, 35.62, 36.02 and 33.20 BLEU scores on the four tasks, setting stateof-the-art results on these tasks. Therefore, our BERT-fused model also benefits unsupervised NMT.

Table content: <table><tr><td/><td colspan="4">En→Fr Fr→En En→Ro Ro→En</td></tr><tr><td>Lample et al. (2018)</td><td>27.6</td><td>27.7</td><td>25.1</td><td>23.9</td></tr><tr><td>XLM (Lample &amp; Conneau, 2019)</td><td>33.4</td><td>33.3</td><td>33.3</td><td>31.8</td></tr><tr><td>MASS (Song et al., 2019)</td><td>37.50</td><td>34.90</td><td>35.20</td><td>33.10</td></tr><tr><td>Our BERT-fused model</td><td>38.27</td><td>35.62</td><td>36.02</td><td>33.20</td></tr></table>

More ablation study on IWSLT'14 En→De.

Table content: <table><tr><td>Algorithm</td><td>BLEU</td></tr><tr><td>Standard Transformer</td><td>28.57</td></tr><tr><td>BERT-fused model</td><td>30.45</td></tr><tr><td>12-layer encoder</td><td>29.27</td></tr><tr><td>18-layer encoder</td><td>28.92</td></tr><tr><td>2-model ensemble (standard)</td><td>29.71</td></tr><tr><td>3-model ensemble (standard)</td><td>30.08</td></tr><tr><td>4-model ensemble (standard)</td><td>30.18</td></tr><tr><td colspan="2">2-model ensemble (BERT-fused) 31.09</td></tr><tr><td colspan="2">3-model ensemble (BERT-fused) 31.45</td></tr><tr><td colspan="2">4-model ensemble (BERT-fused) 31.85</td></tr></table>

BLEU scores IWSLT'14 En←De by BT.

Table content: <table><tr><td>Algorithm</td><td>En→De</td></tr><tr><td>Standard Transformer</td><td>28.57</td></tr><tr><td>BERT-fused model</td><td>30.45</td></tr><tr><td>BT (1M)</td><td>29.42</td></tr><tr><td>BT (2M)</td><td>29.76</td></tr><tr><td>BT (5M)</td><td>29.10</td></tr><tr><td>BT (15M)</td><td>28.26</td></tr><tr><td>BT (25M)</td><td>27.34</td></tr></table>

Comparisons on inference time (seconds), '+' is the increased ratio of inference time.

Table content: <table><tr><td>Dataset</td><td colspan="2">Transformer Ours</td><td>(+)</td></tr><tr><td>IWSLT'14 En→De</td><td>70</td><td>97</td><td>38.6%</td></tr><tr><td>IWSLT'14 De→En</td><td>69</td><td colspan="2">103 49.3%</td></tr><tr><td>WMT'14 En→De</td><td>67</td><td>99</td><td>47.8%</td></tr><tr><td>WMT'14 En→Fr</td><td>89</td><td colspan="2">128 43.8%</td></tr></table>

Peer review (iclr2020):
The paper proposes an approach to incorporate BERT pretrained sentence representations within a NMT architecture. It shows that simply pretraining the encoder of a NMT model with BERT does not necessarily provide gains (and can even be detrimental) and proposes instead to add a new attention mechanism, both in the encoder and in the decoder. The modification is relatively simple, but provides significant improvements in supervised and unsupervised MT, although it makes the model slower and computationally more expensive. The paper contains a lot of experiments, and a detailed ablation study. === I*m very surprised by the results in Table 1, i.e. the fact that pretraining can decrease the performance significantly. The provided explanation *Our conjecture is that the XLM model is pre-trained on news data, which is out-of-domain for IWSLT dataset mainly about spoken languages* is not satisfactory to me. The domain mismatch is also there in the majority of GLUE tasks, SQUAD, etc. and yet pretraining with BERT significantly improves the performance on these tasks. When the encoder is pretrained with a BERT/XLM model, I assume the encoder is not frozen, but finetuned? The description of the algorithm in Section 4 could be simplified a lot I feel. Overall, the attention in the encoder is simply replaced by two attention layers: one over the previous layer like in a standard setting, and one on top of the BERT representation. Also I don*t understand why the attention over the BERT sequence is also necessary in the decoder. Shouldn*t this information already be captured by the encoder output? The Drop-Net Trick is interesting. But the fact that 1.0 gives the best performance (Section 6.2) is very unintuitive to me. This means that the model will never consider the setting with two attentions at training time, although this is what it does at test time. In Table 6, you propose experiments with 12 and 18 layers for fair comparison, because as you mention, your model with BERT-fused has more parameters. But IWSLT is a very small dataset and it would have been surprising that using 18 layers actually helps (overfitting is much more likely in that setting). Instead, I think something like an ensemble model would be a more fair comparison. In fact, the BERT-fused is essentially an ensemble model of the encoder. Could you try the following experiment on IWSLT, where you do not pretrain the BERT model with the BERT objective, but with a NMT encoder trained in a regular supervised setting (i.e. do not reload a BERT model, but a NMT encoder that you previously trained without the fused architecture)? Overall, I think the gains are nice, but I would really like to see the comparison I mentioned just above, and comparisons with ensemble models. The proposed model is significantly larger / slower than the baseline models considered, and I wonder if you could not achieve the same gains with ensemble models. Something I like about the approach is that is it quite generic in the sense that you can provide any external sequence of vectors as input to your encoder. As a result, it is possible to leverage a model pretrained with a different tokenization. Tokenization is often an issue with pretraining in NLP (how do you leverage a model trained without BPE if you actually want to use BPE in your new model). The proposed approach does not has this constraint and I think this is something you should highlight more in the paper. === Small details in the related work section: - I would cite *Sutskever et al, 2014* for the LSTM encoder, along with *Hochreiter & Schmidhuber*, and not only *Wu et al, 2016* - Removing the NSP task was proposed in *Lample & Conneau, 2019*, not in *Liu et al, 2019*