EmotionX-KU: BERT-Max based Contextual Emotion Classifier
Kisu Yang Dongyub Lee Taesun Whang Seolhwa Lee Heuiseok Lim

	*
    Nil Venet[nil.venet@unibg.it, https://nilvenet.org/] and Alessandro Fassò[alessandro.fasso@unibg.it]
     
========================================================================================================


		We propose a contextual emotion classifier based on a transferable language model and dynamic max pooling, which predicts the emotion of each utterance in a dialogue. A representative emotion analysis task, EmotionX, requires to consider contextual information from colloquial dialogues and to deal with a class imbalance problem. To alleviate these problems, our model leverages the self-attention based transferable language model and the weighted cross entropy loss. Furthermore, we apply post-training and fine-tuning mechanisms to enhance the domain adaptability of our model and utilize several machine learning techniques to improve its performance. We conduct experiments on two emotion-labeled datasets named Friends and EmotionPush. As a result, our model outperforms the previous state-of-the-art model and also shows competitive performance in the EmotionX 2019 challenge. The code will be available in the Github page.[<https://github.com/KisuYang/EmotionX-KU>]
	
	
	

§ INTRODUCTION

	
	
	Sentiment analysis, considered as one of the most important methods to analyze real-world communication <cit.>, is a kind of classification tasks to extract subjective information from language.  The traditional sentiment analysis method, <cit.>, returns opinion polarity towards something, but the approach is confined to analyzing just a single sentence or document, regardless of its surrounding information.
	To resolve this issue, <cit.> performed sentiment analysis with datasets that context information has to be considered. Another advanced dataset, Twitter corpus <cit.>, is built from social media more similar to real-world communication. 
	
	
	Under this background, <cit.> released an emotion-labeled corpus of multi-party conversations, EmotionLines, for contextual sentiment analysis. One example of the data set is described in Table <ref>. The example is a situation that a woman and a man are arguing since she has feelings for him but he is watching someone. The last utterance told by Rachel is supposed to be labeled as Joy if it is a single sentence, but it has to be labeled as Anger considering the whole dialogue context.


	

	
	During the recent decade, various neural network models have been proposed to perform this task, arising from their promising performance in many classification tasks. Despite its progress, there are two critical problems of learning long-term dependency <cit.> and processing in parallel <cit.>.
	
	Recently, <cit.> propose a self-attention mechanism that enables to capture long-term dependency and to compute in parallel. The multi-layered self-attention based language model <cit.> drastically advances performances of several natural language processing tasks. We will discuss the pre-trained language models in detail in Section <ref>.

	
	In this paper, we propose the contextual emotion classifier applied to the EmotionX shared task. The proposed model leverages transferable language model and dynamic max pooling to effectively consider each utterance and its context information together. We consider the contextual emotion classification task as a sequence labeling problem in that each utterance has a context in a dialogue. In addition, we propose several machine learning techniques to handle inherent problem of the shared task, which lead to performance gains as a result.
	
	
	
    
	
	The contributions of our paper are as follows:
	
		
  * We suggest a successful method to deal with the intended problems, context understanding, domain adaptation and class imbalance in the EmotionX shared task.
		
  * Our model advances the previous state-of-the-art model, EmotionX-AR <cit.>, by replacing the encoder to a self-attention based transferable language model.
	
	
	This paper is organized as follows. Section <ref> provides a literature review. Section <ref> shows the model description. Section <ref> provides the experimental results and analysis. The conclusion is then provided in Section <ref>.
	
	

	
	
	

§ RELATED WORK

	
	Our study can be positioned in the connection of the following two topics.
	

 §.§ Pre-trained language models

	Pre-trained langauge models, such as ELMo <cit.>, OpenAI GPT <cit.>, and BERT <cit.>, have been broadly applied in a variety of NLP tasks  (e.g., sentiment analysis, machine reading comprehension, and textual entailment) and have achieved a great success.
	
	They can generate the deep contextualized embeddings since they are pre-trained on a massive unlabeled corpus (i.e., English Wikipedia), thus the method built on top of them can achieve better performance. 

	Several researches to leverage pre-trained language models on the task of sentiment analysis have been recently proposed. <cit.> fine-tuned the BERT model and obtained outperforming results on sentiment analysis task. However, they only focused on single sentence classification and did not conduct an experiment on a conversational corpus where each utterance is semantically related. 
	
	
	One of the previous baselines of emotion detection in a dialogue proposes CNN-DCNN auto-encoder based emotion classifier, but they don't utilize the dialogue context information for predicting emotion of utterance <cit.>.
	Our proposed approach takes <cit.>'s and <cit.>'s work one step further by dialogue level with bi-directional pre-trained language model (BERT) on emotion detection, thus the context from both directions on dialogue is reflected much stronger.
	
	

 §.§ Sequence labeling

	
	
	
	
	
	
	
	
	Emotion detection task on a multi-party dialogue is similar to dialogue act sequence labeling task. Dialogue acts are semantic labels attached to utterances in a dialogue that present to briefly identify speaker's intention in producing those utterances.
	
	Dialogue acts identification can be interpreted as a sequence labeling problem and can be resolved naively by assigning a label to each element of the sequence independently. Inspired by the sequence labeling problem in a dialogue-level, we apply this concept to our task. For more details, the dialogue-level tokens are input to the post training language model, which takes into account not only their dialogue emotion, thus modeling the dependency among both, labels and utterances, an important consideration of natural dialogue <cit.>.
	
	
	More related on our task, <cit.> study double embeddings and CNN based sequence labeling for aspect extraction. Aspect extraction is one of the sentiment analysis tasks and aims to extract opinion aspects from opinion based text <cit.>. They achieve very good results on review sentences, but the purpose of these tasks is different from our task in terms of dialogue level. Furthermore, they use pre-trained general-purpose embedding for aspect extraction (e.g., GloVe <cit.>) while we fine-tune the pre-trained language model to be adapted for the dialogue situation.
	
	To the best of our knowledge, this study is the first report such sequence labeling skeleton, especially on the dialogue level, based pre-trained language model for emotion detection.
	
	

§ MODEL DESCRIPTION

	
	The specification of our model is described in this section.
	
	

 §.§ Overview

	We propose a contextual emotion classifier with a combination of transferable language model and dynamic max pooling as in Figure <ref>. (1) Firstly, the input utterances are tokenized according to a byte pair encoding (BPE) algorithm. (2) Then the language model embeds the tokenized inputs into the deep contextualized token representations, which can be sequentially converted to the utterance representations via dynamic max pooling. (3) Finally, the classifier detects contextual emotion, considering the representations.
	

	

 §.§ Input Embedding

	Every utterance is lower-cased and tokenized by the BPE tokenizer, and all the tokens in the same dialogue are appended with inserting the special token, [SEP], between utterances. Exceptively, if we try to append the tokens of the next utterance for building the list of tokens in the dialogue, but it exceeds the preset maximum length of input tokens, the tokens of the utterance are excluded from the list.
	
	The tokens are embedded through WordPiece embeddings <cit.>. The input embeddings, e.g., E_i,l_i where i is the index of utterance and l_i is the length of i-th utterance, are the summation of the token embeddings and the positional embeddings.
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

 §.§ Language Model Encoder

	We adopt transformer <cit.> based pre-trained language model (BERT) because it alleviates the long-term dependecy problem, helping capture the worthy context information effectively. Also, the language model shows the promising high performance, for the pre-trained parameters are transferable into other tasks.
	
	To enhance the adaptability of the language model, we post-train <cit.> the model via masked language model (MLM) and next sentence prediction (NSP). Then all layers of the model are fine-tuned while training for the mentioned emotion classification task.
	
	The language model converts the tokenized inputs, e.g., x = (E_1,1, E_1,2, ..., E_1,l_1), into deep contextualized token representations, e.g., x' = (T_1,1, T_1,2, ..., T_1,l_1). However, each dialogue has different number of utterances, and each utterance has different number of tokens. To handle this problem, we apply a dynamic max pooling technique to create uniform-sized utterance representations from the different number of tokens as in Figure <ref>. It is also considered that the max pooling can assist in keeping important information in each dimension.
	
	

 §.§ Imbalanced Emotion Classification

	The utterance representations from the encoder pass through the classifier what consists of two linear layers, one activation function and dropout as in Figure <ref>. The activation function, scaled exponetial linear units (SELUs) <cit.>, includes normalization processing so that gradient descents can converge more quickly. Dropout is applied to prevent overfitting.
	
	The Friends and EmotionPush datasets suffers from a severe class imbalance problem as in Table 2. To deal with it, we use weighted cross entropy (WCE) as a training loss to weight the samples of minority classes as below.
	
	
    .50!L_WCE=-1N∑^N_i=1w_i·L_CE_i

	
    .30!w_i=∑^N_i=1x_ix_i

	
    .84!L_CE_i=-[y_ilog(p_i) + (1-y_i)log(1-p_i)]

	where N is the number of classes. x_n is the number of samples of class n in a training set. y_n is a ground-truth label, and p_n is a probability for corresponding class n.
	
	
	
	
	
	
	
    
	
	
	
	

§ EMPIRICAL STUDY

	
	We discuss experiment results of our model in this section.
	
	

 §.§ Dataset

	EmotionX 2019 Challenge is a shared task of Social NLP 2019[<https://sites.google.com/site/socialnlp2019/>] that detects emotion in dialogue utterances. Two datasets[<https://sites.google.com/view/emotionx2019/shared-task/datasets>] are released for the challenge, and participants are asked to detect the emotion among four labels (i.e., Neutral, Joy, Sadness, and Anger). One is the Friends dataset <cit.> , which is multi-party conversations collected from one of the famous TV series, and the other is the EmotionPush <cit.> that contains messages collected from social network messengers(e.g., Facebook).
	Each dataset contains 4,000 dialogues including 1,000 English-language original version and 3,000 augmented versions, which is back-translated by French, German, and Italian, respectively. Each dialogue is composed of several utterances and they are labeled with 7 emotions (e.g., Neutral, Joy, Sadness, and etc.). Among the emotions, we regard four emotions (i.e., Fear, Surprise, Disgust, and Non-Neutral) as Out-Of-Domain, since they are not tested on the evaluation phase. 

	In Table <ref>, we describe data and label distribution of Friends and EmotionPush datasets. In terms of label distribution for both datasets, Neutral are the most common class, followed by Joy, Sadness, and Anger. Both datasets have imbalanced class distribution, and especially the ratio of Sadness and Anger is very small. For instance, they account for only 3.4% and 5.2%, respectively in the Friends dataset. In the case of EmotionPush, Anger label accounts for less than 1% of the training set. 

	For the evaluation phase, about 3,000 utterances from 240 dialogues are given to predict one of four emotions. The distribution of two data and classes is similar to the training set of each data.
	
	
	

 §.§ Experimental Setup

	For training our model, the number of epochs and the batch size are set to 10 and 1, respectively. We shuffle the training set for every epoch and also apply gradient clipping method.
	
	
	The learning rate decreases from η^i_max to η^i_min according to a cosine annealing schedule <cit.> as follows:
	
    .91!η_t=η^i_min+12(η^i_max-η^i_min)(1+cos(T_curT_iπ))

	where i denotes the index of the run, and T_cur refers to the number of epochs after the last restart. We set η^i_max = 2e^5 as an initial learning rate and adopt the Adam optimizer <cit.> working with the scheduled learning rate.
	
	We adopt the pre-trained uncased BERT-Base model as the transferable language model where maximum input length is 512. The number of combination layers of a multi-head attention and a feed forward neural network, N in Figure <ref>, is 12. The language model is post-trained via a next sentence prediction (NSP) task and masked language model (MLM) with released Friends, EmotionPush and Emory[<https://github.com/emorynlp/emotion-detection>] <cit.> datasets where the number of  is 100,000 steps. The dimension of hidden representations is set to 768, and the internal hidden size of a classification layer is set to 384. The number of classes is five, including four classes and an out-of-domain class.
	
	

 §.§ Evaluation Metric

	To evaluate the performance of prediction, we mainly use micro f1 score equivalent to weighted accuracy (WA) if every data is tagged with only one class like EmotionLines dataset, obtained by the formula below.
	
	
    .90!micro f1 score = micro-precision· micro-recallmicro-precision + micro-recall

	
	
    .90!macro f1 score = macro-precision· macro-recallmacro-precision +macro-recall

	where
	
    .70!micro-precision = ∑_c∈ CTP_c∑_c∈ C(TP_c+FP_c)

	
    .66!micro-recall = ∑_c∈ CTP_c∑_c∈ C(TP_c+FN_c)

	
	
    .73!macro-precision = ∑_c(TP_cTP_c+FP_c)N_C

	
    .68!macro-recall = ∑_c(TP_cTP_c+FN_c)N_C

	
	

 §.§ Results and Analysis

	
	
	
	
	
	
		
	Experiments are conducted with the released Friends and EmotionPush datasets augmented via back-translation as a training set and their gold datasets for evaluation as a test set.
	
	We assume that the transferable language model which is post-trained with the specific domain corpus predicts the contextual emotion more accurately, and Table <ref> and  <ref> support our hypothesis.
	
	To convert the different length of tokens into the uniform sized representations, we design two converters, dynamic averaging and dynamic max pooling. Even though the former sometimes shows the better performance than the latter as in Table <ref>, the overall performance of the latter is better in the case of training together. Thus, we build our model with post-trained language model and the dynamic max pooling.
	
	When training each dataset seperately compared to training them together, the overall scores on EmotionPush increase, but the performance on Friends dataset decreases. We guess that the parameters of the transferable language model pre-trained with formal corpus might be somehow destroyed when fine-tuning chat-based dialogues, EmotionPush.
	
	For submission version, we implements the k-fold cross validation ensemble method to utilize all the datasets most efficiently where k is 5. Our ensemble model labels each utterance with the most voted emotion based on the decision of k models which are trained with different training set and validation set.
	
	
	
	
	
	

§ CONCLUSION

	
	We proposed the contextual emotion classifier which consists of the transferable language model and dynamic max pooling. Our model successfully alleviates the three inherent problems in the EmotionX shared task, which is to capture contextual information, to understand informal text dialogues and to overcome a class imbalance problem. It outperforms the previous state-of-the-art model and shows competitive performance in the challenge. However, our model cannot consider all the utterances when the number of input tokens exceeds the preset maximum length, so we expect that future work overcomes this problem.
	
	

§ ACKNOWLEDGEMENTS

	This research was supported by the MSIT(Ministry of Science and ICT), Korea, under the ITRC(Information Technology Research Center) support program (IITP-2018-0-01405) supervised by the IITP(Institute for Information & communications Technology Planning & Evaluation)
	
	
	named
	
	
