Attention Calibration for Transformer in Neural Machine Translation (2021)

Abstract: Attention mechanisms have achieved substantial improvements in neural machine translation by dynamically selecting relevant inputs for different predictions. However, recent studies have questioned the attention mechanisms’ capability for discovering decisive inputs. In this paper, we propose to calibrate the attention weights by introducing a mask perturbation model that automatically evaluates each input’s contribution to the model outputs. We increase the attention weights assigned to the indispensable tokens, whose removal leads to a dramatic performance decrease. The extensive experiments on the Transformer-based translation have demonstrated the effectiveness of our model. We further find that the calibrated attention weights are more uniform at lower layers to collect multiple information while more concentrated on the specific inputs at higher layers. Detailed analyses also show a great need for calibration in the attention weights with high entropy where the model is unconfident about its decision.

## introduction attention mechanisms have been ubiquitous in neural machine translation (nmt) @xcite . it dynamically encodes source-side information by inducing a conditional distribution over inputs, where the ones that are most relevant to the current translation are expected to receive more attention. however, many studies doubt whether highlyattended inputs have a large impact on the model outputs. on the one hand, erasing the representations accorded high attention weights do not necessarily lead to a performance decrease @xcite in this paper, we propose to calibrate the vanilla attention mechanism by focusing more on key in-puts. to test what inputs affect the model prediction most, we tend to observe how the model decision changes as perturbing parts of inputs. we define the perturbation operation as applying a learnable mask to scale each attention weight. then, we perform a "deletion game", which aims to find the smallest perturbation extents that cause the significant quality degradation. in this manner, we can find the most informative inputs for the prediction. based on the results detected by the mask perturbation model, we further calibrate attention weights by reallocating more attention to informative inputs. we design three fusion methods to incorporate the calibrated attention weights into original attention weights: (1) fixed weighted sum, (2) annealing learning, and (3) gating mechanism. the mask perturbation model and nmt model are jointly trained, while the attention weights in nmt are corrected based on the actual contributions measured by the mask perturbation model. recall the example in figure 1 . after producing the target word "in", our mask perturbation model finds that the source word "远郊 [countryside]" with a high attention weight is exactly the decisive input for the prediction. therefore, we strengthen the corresponding attention weight of "远郊 [countryside]". however, after the prediction "deaths", the highly-attended " eos " is not the decisive input at the current step. we redistribute the attention weights to the source words ("交通 [traffic]" and "中断 [interruption]") which receive little attention but are important for the subsequent translation discovered by our mask perturbation model. after calibration, the missing source information "traffic interruption" is well-translated. we conduct extensive experiments to verify our method's effectiveness on transformer-based translation (nist zh⇒en, wmt14 en⇒de, wmt16 en⇔ro, wmt17 en⇔fi, and en⇔lv). experimental results show that our calibration methods can significantly boost performance. we further visualize calibrated attention weights and investigate when attention weights need to be corrected. the contributions of this paper are three-fold: ## background in this section, we first briefly introduce the framework of transformer @xcite with a focus on the multi-head attention (mha). then we present an analysis of the learned attention weights, the correlation with feature importance measures, which motivates our ideas discussed afterward. ## our method we aim to make the attention mechanism more focused on the informative inputs. the first step is to discover what inputs are essential for the model prediction. as shown in figure 3 , we design a mask perturbation model to worsen the performance with limited perturbation on the original attention weights. by doing this, we can automatically detect what inputs decide the model outputs. then, we design an attention calibration network (acn) to correct the original attention weights, highlighting the decisive inputs based on what inputs are perturbed by the mask perturbation model. ## experiments we evaluate our method in ldc chinese-english (zh⇒en), wmt14 english-german (en⇒de), wmt16 english-romanian (en⇔ro), wmt17 english-finnish (en⇔fi) and english-latvian (en⇔lv). ## analysis in this section, we explain how our proposed method helps produce better translation by investigating: (1) what attention weights need to calibrate and (2) calibrated attention weights are more focused or more uniform. specifically, we delve into the differences between layers, which give insights into the attention mechanism's inner working. we conduct analyses on zh⇒en nist03 and en⇒de newstest2014 to understand our model from different perspectives. we apply jensen-shannon divergence (jsd) between attention weights before and after calibration to measure the calibration extent: high or low entropy? more focused contributions of inputs suggest that the model is more confident about the choice of important tokens @xcite . we attempt to validate whether the attention weights are more likely to be calibrated when the nmt model is uncertain about its decision. figure 7 shows the positive relationship between calibration extent and the entropy of attention weights. take the 6-th attention layer in zh⇒en translation as an example (as seen in figure 7(b) ). the averaged jsd is 0.0084 for the attention weights in rang [0,0.8], while the value is 0.0324 for the attention weights where the entropy is larger than 3.2. these findings can also be observed at different attention layers and language pairs. we infer that a higher entropy indicates the nmt model relies on multiple inputs to generate the ## related work the attention mechanism is first introduced to augment vanilla recurrent network @xcite , which are then the backbone of state-of-the-art transformer @xcite for nmt. it yields better performance and provides a window into how a model is operating @xcite . this section reviews the recent researches on analyzing and improving attention mechanisms. the attention debate many recent studies have spawned interest in whether attention weights faithfully represent each input token's responsibility for model prediction. serrano and smith flip the model's decision by permuting some small attention weights, with high-weighted components not being the reason for the decision. some work @xcite find a weak correlation between attention scores and other well-ground feature importance metrics, specially gradient-based and leave-one-out methods, in various text classification tasks. we also present the correlation analysis in the lessdiscussed transformer-based nmt and reach a similar conclusion. as opposed to the critiques of regarding attention weights as explanation, wiegreffe and pinter claim that the trained attention mechanisms do learn something meaningful about the relationship between inputs and outputs, such as syntactic information @xcite @xcite . ## conclusion in this paper, we present a mask perturbation model to automatically discover the decisive inputs for the model prediction. we propose three methods to calibrate the attention mechanism by focusing on the discovered vital inputs. extensive experimental results show that our approaches obtain significant improvements over the state-of-the-art system. analytical results indicate that our proposed methods make the low layer's attention weights more dispersed to grasp multiple information. in contrast, high-layer attention weights become more focused on specific essential inputs. we further find a greater need for calibration in the original attention weights with high entropy. our work provides insights on future work about learning more useful information via attention mechanisms in other attention-based frameworks.