How Self-Attention Improves Rare Class Performance in a Question-Answering Dialogue Agent (2020)

Abstract: Contextualized language modeling using deep Transformer networks has been applied to a variety of natural language processing tasks with remarkable success. However, we find that these models are not a panacea for a question-answering dialogue agent corpus task, which has hundreds of classes in a long-tailed frequency distribution, with only thousands of data points. Instead, we find substantial improvements in recall and accuracy on rare classes from a simple one-layer RNN with multi-headed self-attention and static word embeddings as inputs. While much research has used attention weights to illustrate what input is important for a task, the complexities of our dialogue corpus offer a unique opportunity to examine how the model represents what it attends to, and we offer a detailed analysis of how that contributes to improved performance on rare classes. A particularly interesting phenomenon we observe is that the model picks up implicit meanings by splitting different aspects of the semantics of a single word across multiple attention heads.

## introduction many semantic classification tasks have seen a huge boost in performance in recent years @xcite , thanks to the power of contextualized language models such as bert @xcite , which uses a transformer @xcite architecture to produce context-specific word embeddings for use in downstream classification tasks. these large, datahungry models are not always well suited to tasks that have a large number of classes or relatively small data sets @xcite . one task having both of these inauspicious properties is the virtual patient corpus @xcite , a collection of dialogues between medical students and a virtual patient experiencing back pain. the corpus contains examples of nearly 350 questions that the virtual patient knows how to answer, and the interaction is modeled as a text-based conversation in which the human, as the interviewer of the patient, always has the conversational initiative. thus, the corpus represents a question identification task from the perspective of the dialogue agent, in which natural language inputs must be mapped to semantically equivalent classes, so that the appropriate fixed response can be returned to the user to achieve the desired pedagogical objectives. 1 many of the classes in this task are distinguished in subtle ways, e.g., in degree of specificity ("are you married?" vs. "are you in a relationship?") or temporal aspect ("do you @xcite have any medical conditions?" vs. "have you ever had a serious illness?"). a few classes are very frequent, but many appear only once in the data set, with almost three quarters of the classes comprising only 20 percent of the examples @xcite . the current best approach to this task uses an ensemble of text cnns @xcite combined with a rule-based dialogue manager @xcite via a logistic regression model, to leverage complementary performance characteristics of each system on the rare classes @xcite . this approach naïvely treats all classes as orthogonal, so the semantic similarity of the classes above can be problematic. ideally, a model should be able to learn the semantic contributions of common linguistic substructures from frequent classes, and use that knowledge to improve performance when those structures appear in infrequent classes. we hypothesize that multi-headed attention mechanisms may help with this kind of generalization, because each head is free to specialize, but should be encouraged to do so cooperatively to maximize performance. three different methods of utilizing bert-based architectures for this task surprisingly did not improve upon the performance of the cnn models of @xcite . in contrast, a very simple rnn equipped with a multi-headed self-attention mechanism improves performance substantially, especially on rare classes. we assess the reasons for this using several techniques, chiefly, visualization of severely constrained intermediate representations from within the network, and agglomerative clustering of full representations. we find evidence that independent attention heads: 1) represent the same concepts similarly when they appear in different classes; 2) learn complementary information; and 3) may learn to attend to the same word for different reasons. this last behavior leads to discovery of idiomatic meanings of some words. ## related work self-attention, in which a model examines some hidden representation to determine which portions of that representation should be passed along for further processing, became prominent relatively recently @xcite . these models have been very successful for some tasks @xcite , but other approaches may work better for classification tasks with many classes and few examples @xcite . we explore two types of self-attentive models for a virtual patient dialogue task @xcite , which has many classes and scarce data. previous authors have used memory networks @xcite to improve performance on rare classes for this task @xcite . despite the contrast presented above, our selfattentive model actually shares characteristics with the work by @xcite , as we find that individual word tokens carry parallel meanings. we present a detailed analysis of our model's behavior using clustering and visualization techniques; this bears a resemblance to the analysis by @xcite , although they use internal representations to make predictions for linguistic tasks, rather than examining correlations between representations and individual input tokens. ## task and data as described above, our task is a text-based question-answering task for an agent that has a fixed set of responses. the goal is to classify input queries as paraphrases of canonical questions that the agent knows how to answer, so we call this a question identification task. data are collected from actual user interactions with a virtual patient, which is a graphical avatar with a text input interface and subtitles as output. after collection, the system's responses are annotated as correct or not, and if not, annotated with the correct label. @xcite used a data set consisting of 4,330 inputs, comprising 359 classes. we extended this data set by replicating the hybrid system described in their work, and deploying it to collect more data. this resulted in a combined data set of 9,626 examples over 259 dialogues. we noticed that the annotation method for the data used by @xcite introduced a bias for classifications that produce acceptable responses, since only examples deemed to be incorrect were reviewed to identify the correct class. since our evaluation metrics are on the basis of classes and not the agent's responses, we re-annotated every example, with the aim of maximizing the semantic equivalence of members of the same class. this resulted in the elimination and addition of some classes, leaving 348 in the re-annotated set. the long-tailed distribution is no less a problem in the re-annotated set than in the original, but our baseline outperforms theirs since we use cleaner data. we hold out 2,799 examples from the combined set as a test set, and perform tenfold crossvalidation on the training set for development. the test set only contains 268 classes, but fifteen are unseen in the training data (other than the canonical question, see appendix a). ## experimental design and results we start from a text-cnn baseline for this task @xcite , utilizing a single stream system for comparisons. this system convolves glove word embeddings with 300 filters of widths 3, 4, and 5; the max of each filter over the sequence serves as input to a fully connected leaky relu layer @xcite , followed by a softmax layer. we compare this against two contextual models: the relatively well known fine-tuned bert @xcite using the pretrained base model 2 , as well as a variant of a simpler rnn model with system acc. (%) f1 baseline cnn 80.7 55.6 bert fine-tune 79.8 46.6 self-attention rnn 82.6 61.4 bert static cnn 76.9 49.4 bert contextual cnn 75.3 45.2 mean-pool rnn 81.8 59.4 bottleneck rnn 80.8 57.2 training parameters for all three models are provided in appendix a. the development set results (top 3 lines of in particular, the bert model has a very low f1, likely because of the large number of subtly distinguished classes, the relatively small data set, and the high degree of freedom in the bert model. that is, bert may be representing semantically similar sentences in nearby regions of the representation space, but with enough variation within those regions that our training set does not permit enough examples for the classifier to learn good boundaries for those regions. alternatively, the masked language modeling task may simply not induce the grammatical knowledge required to distinguish some classes well. the success of one attention-based contextual model (self-attention rnn) and the failure to improve of another (fine-tuned bert) led us to ask two analytical questions: first, are the bert representations not as appropriate for the virtual patient dialog domain compared to glove embeddings? second, is there something that we can learn about how the attention-based method is helping over the cnn (and particularly on f1)? ## conclusion in some sense, our analysis is unsurprising. words having the same input representations should cluster together in model-internal representations, and members of the same class should similarly cluster. however, we have shown evidence that the selfattentive rnn does some amount of word sense disambiguation that generalizes across classes, and this behavior is driven only by semantic classification. from a human perspective, it makes sense that learning the most generalizable representation should be effective, but it's not clear that a model would need to learn those generalizations in order to perform the classification task. clearly it ben-efits from doing so, so it seems the multi-headed self-attention at least allows for learning these generalizable concepts and the corresponding better optimum. there are some interesting questions and open issues that should be addressed with future work. additional experiments should do more to control for parameter counts; these should be matched for comparisons of the bottleneck rnn to the full selfattentive rnn, to more robustly characterize the effects of the additional nonlinearity in the bottleneck model. the bottleneck representations also seem to reflect something like rudimentary "concepts," insofar as similar semantics often cluster together in the representation space. this raises the intriguing possibility that "metacognitive" processes could improve performance, for example with deductive or abductive inferences about relationships between representations across attention heads. overall, our analysis supports the claim that representations learned in frequent classes are transferring to, and improving performance on, rare classes, and further supports the value of a data set with a large number of subtly distinct classes.