Students Need More Attention: BERT-based AttentionModel for Small Data with Application to AutomaticPatient Message Triage

Small and imbalanced datasets commonly seen in healthcare represent a challenge whentraining classifiers based on deep learning models. So motivated, we propose a novel framework based on BioBERT (Bidirectional Encoder Representations from Transformers forBiomedical TextMining). Specifically, (i) we introduce Label Embeddings for Self-Attentionin each layer of BERT, which we call LESA-BERT, and (ii) by distilling LESA-BERTto smaller variants, we aim to reduce overfitting and model size when working on smalldatasets. As an application, our framework is utilized to build a model for patient portalmessage triage that classifies the urgency of a message into three categories: non-urgent,medium and urgent. Experiments demonstrate that our approach can outperform sev-eral strong baseline classifiers by a significant margin of 4.3% in terms of macro F1 score. The code for this project is publicly available at \url{https://github.com/shijing001/text_classifiers}.


Introduction
Online patients portals, e.g., MyChart by Epic, have become increasingly prevalent tools for communication between patients and healthcare providers (Ramsey et al., 2018). These portals have the potential to boost the productivity of providers, improve patient satisfaction, and reduce communication barriers (Goldzweig et al., 2013;Sieck et al., 2017). Despite these benefits, patient-provider communication tools have produced unintended consequences such as increased, often unpaid, workload for providers (Hefner et al., 2019). Further, due to the flood of non-urgent incoming patient messages, some, which may require a timely emergency response, can be delayed or effectively neglected.
To address these concerns, we consider the task of automated patient message classification to estimate the urgency of messages based on their content. Our dataset consists of 1, 756 messages collected from a University Hospital's portal. These messages, manually adjudicated by experienced healthcare providers, were grouped into three categories: non-urgent, medium, and urgent, as summarized in Table 1. With merely 170 urgent instances, our dataset is both small and imbalanced, posing a significant challenge in terms of properly training machine-learning-based classifiers. This challenge is common in many clinical datasets (Zhao et al., 2018;Para et al., 2019) due to the fact that manually labeling data is very laborious, time-consuming, expensive and oftentimes prohibitive. Further, certain labels are rare by nature, for instance, urgent electronic messages are far less common because patients tend to call the healthcare provider directly rather than using the portal.  Machine learning approaches have been previously applied to message classification tasks in the healthcare domain. For example, Cronin et al. (2015) utilized logistic regression and random forest algorithms to classify between patient health information needs such as symptom management and medication side effects, based on their messages.  studied the use of rule-based and random forest classifiers to classify patient portal messages into broad communication types, e.g., appointment rescheduling, examination enquiry, etc. Sulieman et al. (2017) showed that Convolutional Neural Networks (CNNs) outperform traditional classifiers in portal message classification, and Tafti et al. (2019) developed an ensemble of neural networks for text classification to categorize free-text patient portal messages as either containing active symptom descriptions or logistic requests. Chen et al. (2019) leveraged traditional machine learning methods such as Support Vector Machines (SVMs) to detect hypoglycemia incidents reported in patient messages. To the best of our knowledge, most existing classifiers employ either traditional machine learning methods such as SVMs or shallow networks for the classification of patient generated messages.
Recently, the field of natural language processing (NLP) has seen significant progress in large-scale pre-trained language models, which often considerably boost the performance of classifiers on text classification tasks (Devlin et al., 2018;Radford et al., 2019). Here, we introduce the use of Bi-directional Encoder Representations from Transformers (BERT) (Devlin et al., 2018) for patient message classification. BERT produces sequence representations using a multi-layered attention mechanism, which models associations between the tokens (words) of a sentence (Vaswani et al., 2017). We consider the challenging task of properly training such complex models on a small and imbalanced dataset, which is complicated because these models typically have hundreds of millions of parameters. Previous studies addressed this challenge by pre-training BERT on a large dataset and then finetuning it on the (small) dataset at hand (Devlin et al., 2018). However, the performance of this procedure is usually limited by the size and difficulty of the available small dataset.

Generalizable Insights from Machine Learning in the Context of Healthcare
In this paper we address this challenge with a framework which beyond the use of a pretrained model, has two novel components. First, we introduce a novel attention mechanism that utilizes label embeddings to better capture associations between the labels and the tokens of the input sequence. Importantly, the proposed attention mechanism can be incorporated into existing attention layers with minimum modification, allowing the use of pre-trained BERT or BioBert models (Devlin et al. (2018); Lee et al. (2020)). We term our method LESA-BERT, short for Label Embedding on Self-Attention in BERT. Second, a large deep learning model like BERT has millions of parameters and tends to overfit on small datasets. We hypothesize that a model with a reduced number of parameters may result in a smaller generalization error, thus likely improved performance. Accordingly, we employ the knowledge distillation technique to compress the LESA-BERT model, by training a smaller student model to reproduce the prediction ability of the teacher, a fine-tuned LESA-BERT model. From our framework, we devise distilled variants of LESA-BERT. We demonstrate LESA-BERT by building an automatic message triage classifier that can predict the urgency of messages based on their content. Experiments demonstrate that LESA-BERT and distilled variants result in improved performance compared to multiple baseline approaches. Specifically, LESA-BERT outperforms the baselines by a 2.5% margin in terms of macro F1 score, while the distilled LESA-BERT with 6 encoder layers (Distil-LESA-BERT-6) further outperforms LESA-BERT by 1.8%.

Related Work
BERT Widely used for natural language processing, BERT produces sentence representations through a multi-layered attention mechanism that encodes relations between the tokens that compose the sentence (Vaswani et al., 2017;Devlin et al., 2018). Due to its complex structure, which encompasses a large number of parameters, BERT is typically pretrained on a large dataset and then fine-tuned on the target dataset. Standard pre-training approaches include unsupervised tasks such as masked language modeling and next sentence prediction, which leverage massive unlabeled, general domain corpora like English Wikipedia (2,500M words) or BooksCorpus (800M words) (Zhu et al., 2015). Subsequently, the model is fine-tuned by adding one or more additional layers, the parameters of which are optimized using the target dataset, in a technique termed transfer learning. Recently BERT-based models have been leveraged to NLP tasks in healthcare. Huang et al. (2019) developed ClinicalBERT by pre-training BERT on a large set of clinical notes, and utilized it to predict patients' 30-day hospital readmission based on both discharge summaries and clinical notes. Lee et al. (2020) introduced BioBERT, which is essentially BERT pre-trained on large biomedical corpora that includes PubMed abstracts and PubMed Central full-text articles. They showed that pre-training the model directly on the domain of interest leads to improved performance on various biomedical NLP tasks.
Label Embedding Label embedding is a technique that embeds class labels along with the (text) data into a joint latent space, where the model can be trained to cross-attend the inputs and labels to boost the performance of deep learning models. Label embeddings were previously leveraged for image classification (Akata et al., 2015), multi-modal learning between images and text (Kiros et al., 2014), text recognition in images (Rodriguez-Serrano and Perronnin, 2015), zero-shot learning (Li et al., 2015;Ma et al., 2016) and text classification Zhang et al. (2017). Notably, Wang et al. (2018) proposed a framework named Label Embedding Attentive Model (LEAM), which jointly embeds the words and labels in a common latent space, and improves the performance on general text classification tasks. Inspired by LEAM, we consider the joint representation of the message and its corresponding class token, and propose to incorporate label embeddings to the self-attention mechanism inside BERT encoders, which improves the attention between the class token to the other tokens in the message.
Knowledge Distillation Knowledge distillation is a technique used to train a small model usually called student to reproduce the predictions, thus performance, of a larger model called a teacher (Hinton et al., 2015). It is typically used to compress models, which reduces their storage and computational costs, thus facilitating their deployment. Model distillation has been previously applied to compress complex models such as BERT and LSTMs (Sanh et al., 2019;Tang et al., 2019). When the training data size is small, we hypothesize that the teacher model may be prone to overfitting. In this situation, knowledge distillation is more likely to produce a student model that outperforms the larger, more complex teacher model, as we show in our experiments.

Background
BERT is an architecture composed of a stack of transformer encoder layers, each including two sub-layers: a multi-head self-attention module and a feed forward network. Each of these encoder layers, shown in Figure 1(b), is structured as a residual block with appropriate layer normalization and dropout Ba et al., 2016). In Figure 1(a) we show how to fine-tune BERT-based models on the message urgency dataset to build a classifier. First, each text sequence of length L is prepended with the special token [CLS]. The sum of token and position embeddings, [x [CLS] , x token 1 , . . . , x token L ], are represented as [e [CLS] , e token 1 , . . . , e token L ] and [e 0 , . . . , e L ] vectors, respectively. We use [h [CLS] , h token 1 , . . . , h token L ] vectors to denote the output, high-level representation of classification and input tokens, each of which has the same dimensionality as the input. After applying N (usually N = 12) different encoder layers (of the same structure in Figure 1(b) but different weight matrices), we obtain the high-level representations (output features) of the input sequence, in which each token representation contains information of other tokens. Finally, the first row of the output features, h CLS , is considered as the global sequence aggregator and thus fed through a softmax classification function composed of one or more fully connected layers. The multi-head self-attention module is an ensemble of multiple attention modules sharing the same formulation. Given a text sequence t represented as embedding matrix X ∈ R (L+1)×D , L represents the length of the text sequence and D the token and position embedding dimensions. Note that the first row in X corresponds to the [CLS] token, hence the L + 1 rows in X. For a single-attention head, tokens of [CLS] and the input sequence are first mapped into the key, query and value triplets, denoted as matrices K ∈ R (L+1)×d , Q ∈ R (L+1)×d and V ∈ R (L+1)×d , respectively, via: where {W K , W Q , W V } ∈ R D×d are learnable parameters for the key, query and value of self-attention. With K, Q and V, the attention mechanism can be formulated as where i = 1, . . . , h, h is the number of attention heads, softmax(·) is the softmax function applied row-wise. A is the attention score matrix representing the compatibility of K and Q obtained via inner products. The multi-head self-attention is defined by concatenating and projecting the representation of each head as where [·, ·] denotes column-wise concatenation and W ∈ R (d×h)×D is a learnable projection matrix. After the multi-head self-attention module, the position-wise (one token at the time) feed forward network module in Figure 1(b) composed of two fully connected layers is applied, where max(0, ·) is the standard ReLU activation function, {W 1 , W 2 , b 1 , b 2 } are learnable parameters, and u is the layer normalized residual block u = LayerNorm(x + o), where x (rows of X) and o (rows of O) are the inputs and outputs of the multi-head self-attention module in (1)-(3), respectively, and the LayerNorm(·) operator is implemented according to (Ba et al., 2016).

Multi-head Attention with Label Embedding
For the patient message triage task, the labeled patient text data is usually limited and hard to obtain. Specially, data for the urgent class is scarce but of the highest priority for the application. Therefore, we incorporate label embeddings as prior information into the self-attention modules, so that the model can more easily attend to class-representative keywords. The modified module is shown in Figure 2(a) and described below. We asked healthcare providers to select a set of keywords or short phrases associated with the classes medium and urgent. These are shown in Table 2. The label embeddings of each class is initialized as the average of the corresponding keyword embeddings. The label embedding for non-urgent class is initialized at randomly provided there are no immediately obvious keywords for this class. Below we describe how to incorporate label embeddings into the multi-head self-attention in each encoder layer of BERT. Note that from Figure 1(a), the text sequence t with L tokens, prepended with the token [CLS] as previously described, has embedding matrix X = [x [CLS] , X w ] ∈ R (L+1)×D , where the x CLS and X w are the input embedding vector for  [CLS] and matrix for all other input tokens in the sequence, respectively. Subsequently, the query, key and value matrices in each attention head can be represented equivalently to (1) as where [·; ·] denotes row-wise concatenation, and {q [CLS] , k [CLS] , v [CLS] } and {Q w , K w , V w } are the query, key and value triplets of the [CLS] token and the other input tokens, respectively. From (2), the original attention weights (before softmax) of the augmented sequence can be written as In A BERT , which is equivalent to (2), the cross-attention between the [CLS] token and all input tokens is denoted as S q T [CLS] K T w ∈ R 1×L . In LESA-BERT, we introduce label embeddings to boost the model's attention to keywords associated with different labels. We incorporate label embeddings to self-attention in three steps. First (Step 1), we compute the cross attention between the label embeddings and the message tokens where X l ∈ R 3×D is a matrix containing the three label embeddings, i.e., non-urgent, medium and urgent, which are encoded into label queries Q l via the same W Q as in (5). Next ( Step 2), we compute a modified cross-attention row vector S as where we concatenate S and A l by row and then keep the maximum value of each column. As a result, S represents the maximum attention score of a input token with both the [CLS] token and the label embeddings. Finally ( Step 3), we obtain the attention weights in LESA-BERT by replacing S by S in (6), thus obtaining In (10), when a token is highly relevant to one of the labels it will result in a larger attention score with [CLS] in S , thus the [CLS] embedding will be less affected by irrelevant information in the sequence, unlike (2) where only attention from the current [CLS] embedding is considered. The proposed attention layer is shown in Figure 2(b). The attention score matrix A in (2) is replaced as A LESA−BERT in (10). All other components are exactly the same as the original encoders in BERT as shown in (1)-(4). Note that by incorporating label embeddings to the self-attention layer in BERT model, (9) allows the model to account for label information across all layers. We share the same label embedding for all the layers. The label embedding is adapted to different layers via each layer's W Q s in the multi-head attention module. The label embeddings include trainable parameters, which are tuned simultaneously with other parameters in BERT. If keywords for labels are available, then label embeddings are initialized accordingly, otherwise, label embeddings could also be initialized at random (Wang et al., 2018). All other parameters can be initialized from the pre-trained Bert or BioBert model. Though LESA-BERT is motivated by our application, it can be employed for general text classification tasks.
To the best of the authors' knowledge, LESA-BERT is the first work to incorporate label embeddings to perform self-attention in BERT encoders. Note that this technique could also be applied to models that have the self-attention components such as GPT-2, and transformers (Radford et al., 2019).

Knowledge Transfer with Model Distillation
Knowledge distillation (Buciluǎ et al., 2006;Hinton et al., 2015) is a compression technique, in which a compact model, called the student model, is trained to reproduce the behavior of a larger teacher model, as in Figure 3. In our experiments, we use a loss function defined over the cross-entropy between the teacher and the student class probabilities, given by: where z t and z s are vectors of the output logits from the teacher and student classification networks, respectively, and T 0 is a parameter controlling the degree to which we focus on the class with the highest probability, usually set to 1. When the probabilities softmax(z t /T 0 ) from the teacher model are similar to those of the student model, the cross entropy loss in (11) is small. Therefore, the cross entropy loss measures the difference between output probabilities of teacher and student classifiers. The knowledge distillation technique is typically used to compress large models such as BERT in order to reduce their computational and memory costs; usually to allow their deployment (Buciluǎ et al., 2006;Hinton et al., 2015;Sanh et al., 2019;Tang et al., 2019;Strubell et al., 2019). Here, we hypothesize that, beyond these advantages, knowledge distillation can reduce overfitting in the case of small datasets as is our case. Specifically, we expect a smaller generalization error of the distilled model due to its smaller size. According to this hypothesis, we propose a distilled variant of the LESA-BERT: a small BERT model with fewer encoder layers (student) trained to reproduce the behavior of the finetuned LESA-BERT (teacher), which has 12 layers. In our experiments, we indeed show the improved performance of the distilled model.

Cohort
In this work, we utilized 1,756 web portal messages generated from 10/2014 to 08/2018 by adult patients (> 18 years old) of a large academic medical center. The Electronic Health Record (EHR) system (Epic Verona, WI, USA) with associated patient portal (My-Chart) was the source of all patient messages. A custom-built Application Programming Interface (API) securely made available the portal messages from the EHR enterprise data warehouse into a highly protected virtual network space offered by the medical center. Approved users were allowed access to work with the identifiable protected health information. These messages included free, unstructured plain text sent by patients to their healthcare team. Responses and messages sent from the clinician or health system to the patient were excluded from the analysis. Portal messages were manually labeled by experienced sub-specialty (cardiology) clinicians into three levels of priority: non-urgent, medium and urgent. Non-urgent labels include notes of appreciation (e.g., thank you). The Medium urgency class contains messages that could be reasonably responded to in 1-3 days. Urgent messages are those requiring an immediate phone call to the patient by the clinician. Conditions suggesting acute myocardial infarction, exacerbation of heart failure respiratory distress or possible stroke were labeled as urgent and would be inappropriate for an asynchronous patient portal.
As summarized in Table 1, the data set is imbalanced. Specifically, the total number of messages, 1,756, includes 631 non-urgent, 955 medium and 170 urgent messages. Urgent messages are scarce (∼ 10%), thus the culprit of the imbalance issue. Table 1 also includes a typical example message for each class. For example, an urgent message could be that a patient reports chest pain. In our experiments, the dataset is split into 80% training set (∼ 1.4K) and 20% test set (∼ 0.35K).

Baselines
To evaluate the performance of LESA-BERT, we compare it to strong baseline classifiers of three kinds: (i) traditional machine learning methods: SVM, (ii) shallow neural networks: text CNN and Bi-LSTM with attention layer, and (iii) pre-trained deep learning models: BERT and BioBERT.
SVM: We utilize an 2 regularized SVM classifier (Evgeniou et al., 2000), which optimizes the hinge loss function with a 2 penalty. SVMs are very effective for high-dimensional data (Ghaddar and Naoum-Sawaya, 2018), especially when the number of dimensions is greater than that of samples. SVMs have been widely used for text classification (Tong and Koller, 2001;Dadgar et al., 2016). In our experiments, we implement linear SVM classifiers with the Python module scikit-learn (Pedregosa et al., 2011), and train it via stochastic gradient descent (SGD) with 2 = 6 × 10 −4 penalty coefficient. The learning rate is set by Bottou (2010) and the weights are randomly initialized.
Bi-LSTM with Attention: LSTM, short for long short term memory, is one kind of neural network suited for sequential data. In NLP, bidirectional (forward and backward) LSTMs are usually used as feature extractors for sequences of tokens. On top of the Bi-LSTM layer, the attention layer is introduced to capture important words that drive the decisions of the document classification (Yang et al., 2016). The attention weights are further employed to compute the weighted sum of output vectors of Bi-LSTM as the hidden representation for each message. Then, this representation is fed into a fully connected layer that produces the logits for the three labels. The hidden dimension of Bi-LSTM is set to 60, and the max length of each message is set to 256 tokens. We implement Bi-LSTM with attention model in Pytorch (Paszke et al., 2019), and train it using Adam (Kingma and Ba, 2015) with batch size of 8. The learning rate is 0.01 and the weight matrices are initialized with method in He et al. (2015).
Text CNN: Details of text CNN model can be found in Kim (2014). We set the following parameters for our CNN model: the convolution kernel sizes: {1, 2, 3, 4, 5}, the filter numbers: {200, 300, 500, 500, 200}, dropout probability: 0.5, and maximum number of tokens in each message is 256. Text CNN also comprises maximum pooling layers, as well as the rectified linear unit (RELU) used as the non-linear activation function. The parameters of the network are learned in mini-batches of size 8 using Adam (Kingma and Ba, 2015). The learning rate is 0.01 and the weight matrices are initialized with method in He et al. (2015).
BERT/BioBERT: For BERT and BioBERT, the base uncased, i.e., all words are treated as lowercase, model is employed in this research. BERT base comprises 12 layers, 768 hidden units, 12 self-attention heads, and 110M parameters. These model are trained with warm-up Adam (Gotmare et al., 2019) setting a batch size of 8 and a learning rate of 3 × 10 −5 . The maximum sequence length is set at 256 and other parameters remain the same as the default BERT base configuration. The weight matrices in BERT and BioBERT are set to BERT base uncased (Devlin et al., 2018) and BioBERT v1.1 (Lee et al., 2020), respectively.

Proposed Models
We briefly cover the configuration of our models, which are implemented with Pytorch in a Python 3 environment 1 .
LESA-BERT: LESA-BERT has the same configuration of BioBERT except for its label embeddings, where embeddings of urgent and medium labels are initialized by the average embeddings of their keywords (see Table 2) while the embeddings of non-urgent labels is randomly initialized.
Distil-LESA-BERT: We distill the fine-tuned LESA-BERT model to two variants: one with 6 encoder layers (Distil-LESA-BERT-6), and the another one with 3 (Distil-LESA-BERT-3). The learning rate for these two variants is 2 × 10 −5 and they are initialized from the first 6 or 3 layers of the pre-trained BioBert model accordingly.

Feature Choices
We follow the literature to choose features of each message for the classification task (Sulieman et al., 2017). For traditional classifiers like SVM, TF-IDF features are commonly used. For shallow neural networks like TextCNN and Bi-LSTM with attention, word embeddings such as Word2vec or GloVe are utilized as input features. For BERT-based deep learning models, we just tokenize each message then the model initializes them from pre-training embeddings (Devlin et al., 2018).
For the SVM classifier, we use TF-IDF vectors (Salton and Buckley, 1988) of each message as features. TF represents the frequency of a certain token in a message and IDF represents the inverse of the number of messages in which this token has appeared. The product of TF and IDF for a token is a score that represents the importance of the token in a message. TF-IDF features have been shown to be very effective in text classification (Zhang et al., 2008).
For shallow neural network classifiers like CNN or LSTM models, instead of using TF-IDF, we adopt pre-trained GloVe word vectors (Pennington et al., 2014) as features for each message. We use the 100 dimensional GloVe word vectors pre-trained on 6 billion tokens from Wikipedia and Gigaword data sets. For the BERT-based models including BERT, BioBERT and LESA-BERT, we use the wordpiece tokenizer (Wu et al., 2016) and keep the models' pre-trained token embeddings as initialization, so that the input embeddings are compatible with the models' pre-trained parameters. We utilize the BERT base uncased model with 12 layer encoders and 12 attention heads and 768 dimensional embeddings, which was pre-trained on BookCorpus (Zhu et al., 2015) and English Wikipedia. BioBERT shares the same model configuration as BERT base, but was further pre-trained on biomedical corpora (PubMed abstracts and PMC fulltext articles). Parameters in LESA-BERT except the label embeddings are initialized from the pretrained BioBert model.

Evaluation Metrics
For classification tasks, commonly utilized metric criteria are precision, recall, F1 score and Area Under the Curve (AUC) score. Oftentimes a classifier has a good precision with a poor recall, thus F1 score provides a good balance of precision and recall. AUC is typically employed for binary classifiers. Since the message urgency dataset comprises multiple (three) classes and is imbalanced, we find that macro average F1 score as the most suitable evaluation criteria (Parambath et al., 2014). The F1 score is given by the harmonic mean of precision and recall. Accuracy is a poor metric in this situation because it encourages the model to focus on the majority class. Similarly, micro-level metrics like micro F1 score are not preferred because they are weighted by the number of cases in each label, which makes them favor the majority classes.
We also evaluate the advantages of the distillation process. We distill the fine-tuned LESA-BERT model to 6-layered and 3-layered versions, and evaluate the number of parameters and the inference time required for a full pass on the test set on a CPU with batch size of 1, which are commonly used evaluation criteria for distillation (Sanh et al., 2019). Table 3 presents quantitative results for various classifiers on the test set data. Mean and standard errors are computed based on 5 different random seeds for the SGD/Adam training algorithm. The F1 scores for shallow neural networks, i.e., TextCNN and Bi-LSTM attention, are slightly better than SVM, which might be owed to the benefits of semantic features captured by GloVe word vectors. BERT-based deep neural networks such as BERT and BioBERT only marginally outperforms Bi-LSTM attention and TextCNN, which is likely caused by the small size (∼ 1.4K) of the training data. The F1 score of BioBERT is 0.3% higher than that of BERT, which means that pre-training on large biomedical corpora transfers extra beneficial information to BERT model. In terms of macro average F1 score, our LESA-BERT and its distilled variants achieve higher F1 scores compared with other classifiers. The performance gains can be attributed to the addition of the label embeddings.

Quantitative Results
The model Distil-LESA-BERT-6 provides higher F1 score (0.807) than that of the full 12-layered LESA-BERT. Possibly, this implies that the full model overfits the training set, while the distilled model with 6-layers reduces the overfitting. Distil-LESA-BERT-3 model, which comprises only 3 layers provides F1 score of 0.78, slightly lower than the full LESA-BERT model. Table 4 presents the number of parameters in LESA-BERT and its distilled variants, as well as inference times for a full pass over the test set with batch size of 1. As the number of layers in LESA-BERT decreases, the number of parameters and inference time reduces dramatically. Distilling the original 12-layered LESA-BERT to 6 layers reduces the number of parameters by 40% and accelerates the inference by 2.7 times. Distil-LESA-BERT-3 has fewer parameters and faster inference speed than Distil-LESA-BERT-6. Taking into account their F1 scores, Distil-LESA-BERT-6 outperforms the LESA-BERT, and Distil-LESA-BERT-3 retains 98.9% of LESA-BERT performance. Distil-LESA-BERT-6 provides the best F1 score compared to all other methods. However, in the case that inference time is preferred, Distil-LESA-BERT-3 will be the top choice.

Qualitative Results
In Figure 4, we visualize how the obtained representation by LESA-BERT attend to different tokens in three example messages, one for each class. Tokens are shaded in terms of their importance for classification. Dark-colored tokens are more prominently weighted (attended) when constructing the message embedding. As seen in Figure 4, attention scores can identify relevant keywords in all three examples. We choose these three examples because they are representative in their respective categories.  messages of the other two classes. For the urgent and medium classes, their data points have significant overlap, meaning that urgent and medium messages, not surprising, have similar characteristics (features). This may be in part caused by the subjectiveness of the labeling process as the definitions of urgent and medium messages are not exactly clear.

Discussion
We have proposed a framework for building classifiers on small and imbalanced datasets, which is a commons scenario in healthcare. Our method builds upon a large deep learning model, BioBERT, which was pre-trained on huge general-domain and biomedical corpora. We developed LESA-BERT, which has a novel self-attention architecture that can incorporate label embeddings to boost the model's capacity for attention. We fine-tuned LESA-BERT on the target dataset by initializing its parameters from BioBERT. Subsequently, we distilled the fine-tuned 12-layered LESA-BERT to 6-layered or 3-layered variants, and found that the 6-layered Distil-LESA-BERT outperforms the 12-layered LESA-BERT. Therefore, knowledge distillation is not only a tool for model compression, but can also be used to reduce overfitting. We demonstrated the application of our framework on a real healthcare dataset -message urgency-and built a message triage classification model. Our methods outperformed baseline classifiers by a significant margin. Our technical solution can be easily applied to other clinical datasets.
Clinical Implications We built an automatic message triage model that can predict the priority of patient portal messages based on their content. This version of message triage could be further improved with a larger dataset to train our classifiers. The message triage system is of real impact to healthcare providers and potentially save valuable working hours by freeing them from reading patient portal messages in chronological order. Promptly accessing and realizing urgent messages can impact both patient safety as well as clinician workflow. After the message triage classifier produces the priority of messages, healthcare providers can take further actions based on their existing workflow. Further, they may want to utilize automatic responses or templates to answer non-urgent messages. Medium or time-sensitive messages may either be directed to emergency rooms, urgent care or telephone encounters.
Limitations Although our methods outperform a wide selection of baseline models, it can still produce some mistakes from a human perspective. For instance, Figure 5 shows that two non-urgent messages (purple dots) fall in the region of medium and urgent labels. In fact, we have investigated these very few messages that are close to medium or urgent messages, and one example reads "No chest pain at all". This message has very strong keywords, chest pain, which usually appears in urgent messages. Therefore, the LESA-BERT model maps this message to urgent class by ignoring the negation word "No". Many researchers have found that deep learning models are powerful but still easy to fool (Moosavi-Dezfooli et al., 2016;Heaven, 2019). As future work we plan on incorporating negation detection (Qian et al., 2016) into our classification framework.
Our current message triage system has a few limitations from the clinical perspective. Firstly, our message classifier only has three levels of urgency, which could be further refined into more granular categories. After passing patient portal messages through our urgency classifier, urgent messages will be treated with priority, but non-urgent and medium ones will probably need further automatic classifiers, such as message intention detector, etc. Secondly, our current work is limited to only utilizing the content of portal messages. One possible follow-up research could be to incorporate patient's demographic information or even comorbidities. For example, age can be quite important when deciding the priority of messages. Messages from patients aged over 65 should receive relatively more immediate attention than younger patients. Comorbidities could also be taken into account as patients with heart attacks, for example, usually get more intense care than patients with, for example, common respiratory infections.
Yang Zhao, Zoie Shui-Yee Wong, and Kwok Leung Tsui. A framework of rebalancing imbalanced healthcare data for rare events classification: a case of look-alike sound-alike mix-up incident detection. Journal of healthcare engineering, 2018, 2018.
Yukun Zhu, Ryan Kiros, Rich Zemel, Ruslan Salakhutdinov, Raquel Urtasun, Antonio Torralba, and Sanja Fidler. Aligning books and movies: Towards story-like visual explanations by watching movies and reading books. In Proceedings of the IEEE international conference on computer vision, pages 19-27, 2015.