Wat zei je? Detecting Out-of-Distribution Translations with Variational Transformers

1 INTRODUCTION . Statistical Machine Translation ( SMT , ( Brown et al. , 1993 ; Och , 2003 ) ) , built on top of probabilistic modelling foundations such as the IBM alignment models ( Vogel et al. , 1996 ; Brown et al. , 1993 ; Gal & Blunsom , 2013 ) , has largely been replaced in recent years following the emergence of Neural Machine Translation approaches ( NMT , ( Kalchbrenner & Blunsom , 2013 ; Bahdanau et al. , 2015 ; Luong et al. , 2015 ; Vaswani et al. , 2017 ) ) . This change has brought with it huge performance gains to the field ( Sennrich et al. , 2016 ) , but at the same time we have lost many desirable properties of these models . Statistical probabilistic models can inform us when they are guessing at random on inputs they never saw before ( Ghahramani , 2015 ) . This information can be used , for example , to detect out-of-training-distribution examples for selective classification by referring uncertain inputs to an expert for annotation ( Leibig et al. , 2017 ) , or for a human-in-the-loop approach to reduce data labelling costs ( Gal et al. , 2017 ; Walmsley et al. , 2019 ; Kirsch et al. , 2019 ) . With new tools in machine learning we can now incorporate such probabilistic foundations into deep learning NLP models without sacrificing performance . This field , known as Bayesian Deep Learning ( BDL , ( Neal , 2012 ; Gal , 2016 ) ) , is concerned with the development of scalable tools which capture epistemic uncertainty—the model ’ s notion of “ I don ’ t know ” , a measure of a model ’ s lack of knowledge e.g . due to lack of training data , or when an input is given to the model which is very dissimilar to what the model has seen before . Such BDL tools have been used extensively in the Computer Vision literature ( Kendall & Gal , 2017 ; Litjens et al. , 2017 ) , and have been demonstrated to be of practical use for applications including medical imaging ( Litjens et al. , 2017 ; Nair et al. , 2020 ) , robotics ( Gal et al. , 2016 ; Chua et al. , 2018 ) , and astronomy ( Hon et al. , 2018 ; Soboczenski et al. , 2018 ; Hezaveh et al. , 2017 ) . In this paper we extend these tools , often used for vision tasks , to the language domain . We demonstrate how these tools can be used effectively on the task of selective classification in NMT by identifying source sentences the translation model has never seen before , and referring such source sentences to an expert for translation . We demonstrate this with state-of-the-art Transformer models , and show how model performance increases when rejecting sentences the model is uncertain about—i.e . the model ’ s measure of epistemic uncertainty correlates with mistranslations . For this we develop several measures of epistemic uncertainty for applications in natural language processing , concentrating on the task of machine translation ( §3 ) . We compare these measures both with standard deterministic Transformer models , as well as with Variational Transformers , a new approach we introduce to capture epistemic uncertainty in sequence models using dropout approximate inference ( Gal , 2016 ) . We give an extensive analysis of the methodology , and compare the different approaches quantitatively in the out-of-training-distribution settings ( §4 ) , which shows our proposed uncertainty estimate BLEUVar works well for measuring the epistemic uncertainty for machine translation . We also analyse the performance of BLEUVar qualitatively from both the influence of sentence length and from the linguistic perspective . We finish with a discussion in potential use cases for the new methodogy proposed . The closest NLP task to the above problem definition is the quality estimation ( QE ) task in Machine Translation ( Specia et al. , 2010 ; Blatz et al. , 2004 ) , which tries to solve a similar problem by predicting the quality of a translation with a score called Human Translation Error Rate ( HTER , ( Snover et al. , 2006 ) ) . This is done by training a surrogate QE model on source sentences and their corresponding machine-generated translations in a specific domain , with the target of the surrogate to predict the the percentage of edits needed to be fixed . While many methods have been shown to successfully solve the task of estimating the quality of translations ( Kim et al. , 2017 ; Martins et al. , 2016 ; 2017 ; Kreutzer et al. , 2015 ) , by definition QE crucially relies on examples of mistranslations to train the surrogate . The assumption that such training data is available is often violated in practice though ( e.g . in active learning ) , thus existing approaches in QE research can not generally be used to detect out-of-training-distribution examples ( see Appendix C for detail discussion about the differences between QE and our task , as well as other related work that is similar to ours but not solving the same problem ) . 2 BACKGROUND : UNCERTAINTY IN DEEP LEARNING . For most machine learning models , the optimisation objectives give us a point estimate of the model parameters , which maximise the likelihood of the model generating the training data ( i.e . p ( Y |X , ω = ω∗ ) , ω∗ ∈ Ω s.t . Ω is the set of all possible model parameters , Y , X are the training data ) . Such point estimate ω∗ gives us a very good prediction when the test data follow the same distribution as the training data distribution . Given a new input x∗ at test time , the model prediction for the corresponding y∗ is ŷ∗ = arg max y∗ p ( y∗|x∗ , ω∗ ) . ( 1 ) However , we can not expect the model to perform well on out-of-distribution ( OOD ) data which it never saw before . Instead , we would wish for the model to indicate its uncertainty towards such inputs . We could use p ( ŷ∗|x∗ , ω∗ ) as an estimate for model uncertainty , but as we show below , it would not be a well calibrated one . It might be the case that many ω might give equally good predictions on the train set , but might widely disagree with their predictions on OOD data . In fact , ω∗ might give arbitrary predictions on OOD training data which is very dissimilar to previously observed inputs . Thus , a high score does not distinguish whether x∗ is OOD or not , and whether we should trust the model ’ s prediction . 2.1 BAYESIAN INFERENCE . Bayesian probabilistic models capture the notion of uncertainty explicitly . Rather than considering a single point estimate ω∗ , Bayesian models aim to capture the entire distribution of ω from the training data . The resulting distribution is called posterior distribution p ( ω|X , Y ) = p ( Y |X , ω ) p ( ω ) p ( Y |X ) . ( 2 ) At test time , we can make prediction about the corresponding y∗ by integrating out all possible ω p ( y∗|x∗ , X , Y ) = ∫ p ( y∗|x∗ , ω ) p ( ω|X , Y ) dω . ( 3 ) Using the variance of the predictive distribution p ( y∗|x∗ , X , Y ) as the uncertainty measure would have taken into account the variance of ω . Hence , an uncertainty measure based on this quantity could be a strong indicator for x∗ being OOD . 2.2 APPROXIMATE INFERENCE . The difficulty in doing Bayesian inference comes from the intractability of calculating the evidence p ( Y |X ) = ∫ p ( Y |X , ω ) p ( ω ) dω . ( 4 ) There might be a closed form solution for a simple model . But for most interesting problems , it is too difficult to compute an exact solution . Therefore , approximations are often used for such inference problems . Variational inference ( VI ) is a pragmatic popular method for doing approximate inference ( Jordan et al. , 1999 ) . The method involves defining an approximating distribution qθ ( ω ) , and trying to find the parameter θ for that minimises the Kullback-Leibler ( KL ) divergence ( Kullback & Leibler , 1951 ) between qθ ( ω ) and the posterior KL ( qθ ( ω ) ‖p ( ω|X , Y ) ) = ∫ qθ ( ω ) log qθ ( ω ) p ( ω|X , Y ) dω . ( 5 ) The resulting θ∗ gives us the closest approximation for the posterior in the family of distribution qθ ( ω ) . However , calculating the KL divergence here is also intractable as we still have to do the integration for the evidence in posterior . Fortunately , a tractable and equivalent objective for minimising the KL divergence is to maximise the evidence lower bound ( ELBO , ( Blei et al. , 2017 ) ) of qθ ( ω ) ELBO ( qθ ) = ∫ qθ ( ω ) log p ( Y |X , ω ) dω −KL ( qθ ( ω ) ‖p ( ω ) ) . ( 6 ) This is tractable as we know all the distributions ( both qθ ( ω ) , p ( Y |X , ω ) and p ( ω ) are defined by the model or by our assumptions ) . 2.3 BAYESIAN INFERENCE IN DEEP LEARNING . Almost all deep models treat the units in a deep neural network as deterministic functions . To adapt Bayesian methods in deep learning , we need to first turn our model into a probabilistic model . It can be done by modelling the weights in each unit of the network as samples from probability distributions . Such networks are called Bayesian neural networks ( Neal , 2012 ) . One major challenge with Bayesian neural networks is that the integration in ELBO becomes intractable when we have more than one hidden layer ( Gal , 2016 ) . Many works have tried tackling this problem . One practical method proposed by Gal ( 2016 ) is MC Dropout . Gal ( 2016 ) showed that optimising any neural networks with dropout can be viewed as an approximate inference in a probabilistic model ( when dropout p is tuned correctly ) , which implies that a trained neural network with dropout can be interpreted as a Bayesian neural network Gal ( 2016 ) . Stochastic forward passes with dropout ‘ turned-on ’ at test time then correspond to draws from the predictive distribution . Here we extend on these ideas and propose the Variational Transformer , which is based on MC Dropout applied to the original Transformer model . We perform extensive empirical evaluation with this model on the task of NMT . Representing uncertainty in a translation model is the first step towards detecting OOD data . We next discuss how to use this uncertainty effectively , and provide the main contribution of this work . 3 MEASURES OF UNCERTAINTY FOR NMT . Principally , we care about measuring the variance of a model ’ s outputs around some given input point . In the context of a simple classifier model , the solution is often found by measuring the mutual information between the predicted discrete distribution and model parameters , evaluating the output ’ s entropy , or simply computing the variance of model outputs ( Gal , 2016 ) . In the domain of language , however , there are many semantically equivalent alternatives to the same prediction , and it is a difficult matter to measure the disagreement between the predicted discrete sequences , which in turn complicates the estimation of variance in the output space . Much worse , when attempting to naively use MI or entropy with long sequences or large sets of discrete random variables , we quickly discover that even approximate integration over the product space becomes prohibitive ( Kirsch et al. , 2019 ) . In order to capture epistemic uncertainty in the task of NMT , we propose several measures of uncertainty appropriate for long sequences of discrete variables ( Beam Score and Sequence Probability are measures similar to ( Wang et al. , 2019 ; Fomicheva et al. , 2020 ) ) : 1 . Beam Score : we assign a confidence to output y generated ( using beam search ) from input x using the score assigned to y ’ s beam ( Wu et al. , 2016 ) , where length_penalty ( y ; α ) = ( 5+|y| 5+1 ) α . BS = log ( pω∗ ( y|x ) ) length_penalty ( y ; 0.6 ) ( 7 ) 2 . Sequence Probability : we assign a confidence to the deterministic model output y generated from input x by taking the log predictive probability under the weight distribution . SP = log ( Eω∼qθ∗ ( ω ) pω ( y|x ) ) length_penalty ( y ; 0.6 ) ( 8 ) 3 . BLEU Variance : ideally , we would like to measure the variance of outputs y as the uncertainty at an input x , i.e . : Var = Eω∼qθ∗ ( ω ) Ey∼pω ( y|x ) ( y − µ ) 2 = Eω∼qθ∗ ( ω ) Ey , y′∼pω ( y|x ) 1 2 ( y − y′ ) 2 , ( 9 ) where µ = Ey∼pω ( y|x ) [ y ] . If we treat sentences as points in some high dimensional space , ||y−y′|| corresponds to a distance between these two points , which is a numerical value representing the difference between two sentences . Thus , any metric for measuring the difference between sentences will allow us to calculate the variance of output y . In our experiments we choose BLEU ( Papineni et al. , 2002 ) . The BLEU score of a candidate text to the reference text is a number between 0 and 1 , with the value closer to 1 indicating the two texts are more similar1 . Now , we can estimate the variance at an input x by producing pairs of outputs from the model and measuring the squared complement of the BLEU between them , i.e . ||y − y′||2 : = ( 1− BLEU ( y , y′ ) ) 2 , and we have : BLEUVar = Eω∼qθ∗ ( ω ) Ey , y′∼pω ( y|x ) ( 1− BLEU ( y , y ′ ) ) 2 ( 10 ) For the beam score we use the deterministic model found by gradient descent and simply take the probabilities from under its output probabilities . This will be our baseline . For sequence probability and BLEU variance we use MC Dropout ( Gal , 2016 ) and take a number of samples ( N ) to estimate the expectations2 : SP ≈ log ( ∑N i=1 pωi ( y|x ) ) length_penalty ( y ; 0.6 ) ( 11 ) For the BLEUVar approximation , we opt for decoding outputs using beam search applied to different model samples ( realised by randomising the dropout masks ) and measuring the complement BLEU between pairs of these examples . BLEUVar ≈ N∑ i=1 N∑ j 6=i ( 1− BLEU ( decωi ( x ) , decωj ( x ) ) ) 2 . ( 12 ) Additionally , out of the N sample sequences generated by BLEUVar , we need to choose one or generate a new sequence as the result for a specific input . In regression , the mean of the samples is normally chosen as the result , which is an approximation for the predictive mean . In our case , the ‘ mean ’ of N sentences is hard to derive or even not properly defined . Therefore , we use the sampled sequence that is the closest to the ideal ‘ mean ’ as an approximation . Since we can measure the disagreement between any two sentences using BLEU , the sequence that is the closest to the ‘ mean ’ of the N samples must have the smallest disagreement with rest of the N − 1 samples . Hence , the final output sequence of the method BLEU Variance is : µ̃ = arg min yi ( N∑ ∀j 6=i ( 1− BLEU ( yi , y′j ) ) + N∑ ∀j 6=i ( 1− BLEU ( y′j , yi ) ) ) . ( 13 ) One remark for the above three methods is that the two methods BS and SP have the same resulting translation y given x , but with different values as its uncertainty estimates . For the method BLEUVar , it uses µ̃ for the resulting translation , and a value in a different range as the uncertainty estimate . This is reflected in the plots from the experiments section . For example , in Figure 6 ( b ) , BS and SP converged into the same value , while BLEUVar converged to a different value .

Summary: This paper describes a method for estimating a neural machine translation (NMT) system's uncertainty about its translation of a sentence that has two parts: (1) use MC Dropout as a proxy for integrating out parameters; (2) two uncertainty metrics (probability of translation summing over randomly-sampled parameters and variance in BLEU using randomly-sampled parameters). The baseline method is just to use the probability of the 1-best translation under the MLE parameters. The method is evaluated by measuring the BLEU score of a test set retaining only the most-certain fraction of the sentences.