Translation vs. Dialogue: A Comparative Analysis of Sequence-to-Sequence Modeling (2020)

Abstract: Understanding neural models is a major topic of interest in the deep learning community. In this paper, we propose to interpret a general neural model comparatively. Specifically, we study the sequence-to-sequence (Seq2Seq) model in the contexts of two mainstream NLP tasks–machine translation and dialogue response generation–as they both use the seq2seq model. We investigate how the two tasks are different and how their task difference results in major differences in the behaviors of the resulting translation and dialogue generation systems. This study allows us to make several interesting observations and gain valuable insights, which can be used to help develop better translation and dialogue generation models. To our knowledge, no such comparative study has been done so far.

## introduction the sequence-to-sequence model (seq2seq), especially its enhanced variants of long short-term memory (lstm) @xcite and gated recurrent units (gru) @xcite , have been demonstrated to be highly effective for a variety of nlp tasks, e.g., machine translation (mt) @xcite , dialogue response generation (drg) @xcite , and many others. a seq2seq model takes in a source sentence (a sequence) and generates a target sentence (another sequence). this model was first proposed for mt by translating a source language into a target language. it is now also widely used for drg to "translate" an input utterance from the user to an output response. traditional feature-engineering solutions to mt and drg require a large number of handcrafted features. in end-to-end learning, seq2seq models require almost no manual features for mt or drg. the model is purely driven by data: when trained on the translation data, the model learns to translate; when trained on the conversational data, the model learns to converse. however, this approach also makes the neural model hard to understand or interpret. to this end, researchers have proposed to understand and visualize recurrent neural networks @xcite and neural machine translation (mt) models @xcite . as we know, mt and drg are two very different tasks. but the same seq2seq modeling works for both, which is counter-intuitive. however, recent studies for understanding neural models have primarily focused on a single task. this paper proposes to study the seq2seq model comparatively in the contexts of two tasks, mt and drg. since the two very different tasks use the same model, the internal network behaviors of the model must be very different for the tasks. our comparative study shows the contrast, which enables us to see a clearer picture of the model for each task and its issues, which cannot be easily observed from the model behaviors of only a single task. this paper aims to answer the following research questions: we answer these important questions starting from analyzing the difference in data for mt and drg as end-to-end models are data-driven. the objectives of the tasks are embedded in the training data only. we will then study how the different task data lead to different model behaviors in embedding, attention, hidden states, and decoding alignments. these analyses will allow us to answer the above research questions. the seq2seq model has been shown to have excellent performance for both mt @xcite and drg @xcite . however, to understand how and why it is effective on different tasks remains to be a challenge. understanding neural models: visualization techniques have been explored in computer vision to understand neural networks @xcite @xcite @xcite . for visualization methods in nlp, a few ablation studies have analyzed the effects on performance of several internal neural units in specific nlp tasks @xcite @xcite . the earliest visualized neural unit was the word embedding, which projects the word embedding space into a 2-dimensional space and observes that words with similar meaning tend to cluster together @xcite . @xcite described strategies for visualizing compositionality in neural models (mainly focused on some specific nlp tasks such as sentence classification), including the first-order derivatives and the variances. @xcite focused on mt and proposed to use layer-wise relevance propagation to compute the contribution of each contextual word to arbitrary hidden states in the attention-based encoder-decoder framework. unlike previous works, this paper performs a comparative study of the seq2seq model for mt and drg. to our knowledge, this has not been done so far. it analyzes and visualizes different behaviors of the seq2seq model for mt and drg to answer the proposed research questions. ## datasets analysis we start our investigation from the most direct source of difference: the characteristics of the data for mt and drg. the following datasets are used in our analysis. mt dataset: for mt, our training dataset consists of 2.08m sentence translation pairs in different languages, extracted from the ldc corpus. we use nist 2003 chinese-english dataset as the validation set, and nist 2004-2006 datasets as test sets. each nist dataset has 4 different reference translations for each sentence, and we also call it the multi-reference dataset (mrd). dialogue dataset: we use the twitter dataset @xcite for english and a question and answer dataset about movies @xcite for chinese which has 1.61m sentence pairs. we randomly selected 2k sentence pairs from the corpus for testing and another 2k sentence pairs for development. to analyze the diversity in replies, we asked 4 ph.d. students to reply 300 queries in any way they see fit and use their replies as the multi-references for dialogues. ## ability of training embedding word embedding plays a vital role in seq2seq models. considering the decoding process, it is hard for the decoder to predict the correct words if word embeddings are unable to cluster similar words together. here, we compare the word embedding quality of mt and drg dased on similarity and analogy. training details: for a fair comparison, we employ the same open-source seq2seq platform foot_2 @xcite to train both the mt and drg models. the hyper-parameters in our system are described as follows. we limit the vocabulary to 30k in our experiments. the size of hidden units is 600 and the word embedding dimension is 300. we set the number of layers of lstm to 2 in both encoder (bi-directional encoder is adopted) and decoder. the network parameters are updated using the adam algorithm (kingma and ba, 2014) with learning rate of 0.0001. for the final decoding at test time, we adopt the beam search with beam size @xmath0. a large beam size for dialogues tends to generate trivial or universal responses like "i don't know". the evaluation results of the seq2seq model applied in the dialogue experiment achieves 9.75, 1.06, 0.14, 0.043 for bleu 1 to 4 respectively, which are better than the results reported in @xcite . ## analyzing attention and hidden states in addition to embeddings, attention is also an important mechanism for seq2seq models. ## analyzing the final prediction in seq2seq models, the attention-based encoding and the decoder hidden states are two important constituent parts for making the final prediction. exploring their contributions to the final decision can help nlp researchers to design better models. we propose a new combinational disturbance approach to measuring how much each input unit contributes to the final decision. first, we need to introduce the first-derivative salience method @xcite . drg mt drg mt var 5.73 9.13 sim 0.730 0.496 ## decoding confidence the entropy of decoder output distribution ϕ (described in section 6) can be regarded as a representation of how confident the model is at the current decoding time step t. it can be calculated by s(ϕ t ) = l -ϕ t,v ln(ϕ t,v ). v denotes the v-th word in the vocabulary. in this case, smaller entropy means more confidence in decoding. case comparison. we first explore the decoding confidence at each decoding position for both mt and drg systems. fig. 5 shows the entropy heat map for six cases randomly sampled from the test sets, from where, we can make the following observations: • the entropy of mt is generally lower than that of drg . that is, the decoder is more confident in mt due to the strong supervision from the inputs and the nature of the task. due to the high diversity of drg without strong supervision, the decoder in drg is not very confident in decoding. to further verify the observations, we select sentences with fixed lengths to decode, and compute average entropy at each position. the same phenomenons are observed in fig. 7 . ## error analysis this section investigates the conditions that a correct prediction is likely to be made by the model. we use negative log-likelihood (nll) as the metric to measure the correctness of the model's prediction. nll is a negative log function of the prediction probability of ground-truth and it can be calculated by s @xmath1. in our case, p i is the prediction probability for the i-th correct word in the given replies (or translations) predicted by the seq2seq model. to alleviate the influence of the high diversity problem discussed before, we use teacher-forcing @xcite in this experiment. a good prediction has a small nll. as for the sentence level measurement s, we average all the s i in the sentence, that is, @xmath2, where l is the sentence length. extensive experiments have been conducted to investigate many possible factors that may cause the model to make mistakes (or higher nll), including: the position of the decoding word, the average of hidden state change volume over the whole prediction, word frequency, attention distribution (introduced in section 5), and the length of generation. we found that word frequency and attention distribution have clear correlation with the correctness of prediction (nll). the rest of the factors show little correlation. fig. 9 shows the correlation between the word frequency and nll of the drg system and mt system. we can see that both mt and drg systems have a tendency to make mistakes on low frequency words and perform well on high frequency words. this phenomenon indicates that words with higher frequency are trained better by the model, yielding better performances. this phenomenon can also be regard as an imbalanced prediction problem in drg and mt. thus, balancing or increasing word frequency can help the model get better results. pearson coefficient and spearman coefficient are calculated to measure the degree of correlation between word frequency and nll. their results are given at the top of fig. 9 . we can see a higher correlation between word frequency and nll scores in drg. that is because the high diversity phenomenon of drgs such that it is harder for the seq2seq model to capture the correspondence between the source and target when the word frequency is low. as a result, drg is more sensitive to word frequency than mt. in section 5, we analyzed the attention distribution. here we found that attention distribution can clearly indicate the accuracy of the predicted words or sentences in mt. similar to but also different from section 5, here we use entropy to measure the attention dispersion of each word/step over the source language inputs. intuitively, a larger entropy corresponds to a more dispersed attention. we use the average of the entropy values at all decoding steps as the measure of the degree of attention concentration of the whole sentence. fig. 10 shows the correlation between the entropy (degree of attention concentration) and nll (which reflects the quality of the generated target sentence). it can be easily observed that the performance of mt is closely related to the degree of attention concentration. the pearson coefficient and spearman coefficient shown in the figure are much higher than those coefficients for drg. we can see that when the attention is focused (i.e., the weight gathers on a few tokens) the model has less tendency to make mistakes. errors are more likely to occur when the attention mechanism cannot generate a focused weight distribution. while for drg, the performance is not closely related to the degree of attention concentration for both pearson and spearman coefficients, smaller than 0.03. the reason for the difference of the two systems or applications is that there is a clear word alignment relationship in mt, which is not the case for drg. the word alignment relationship provides a strong supervision for the decoding step in translation. a dispersed attention indicates that the current prediction has a high-level of uncertainty and thus tends to make mistakes. due to the high data diversity problem, drg lacks a clear alignment relationship between source and target, and thus the degree of attention concentration cannot reflect the quality of the generated target sentence. ## summary of the comparative study we now summarize the study by answering the four proposed research questions. 1. what are the differences in the network internals and why are they different for the tasks? the answer is that for all the analyzed items, the network internals behavior differently for different tasks. the reason is due to the data difference of the two tasks, which reflects the nature of the two tasks. the possible responses for an input query in drg can be highly diverse, much more than possible translations of a sentence in mt.