Year: 2020

Abstract:
Transformer-based pre-trained language models have proven to be effective for learning contextualized language representation. However, current approaches only take advantage of the output of the encoder’s final layer when fine-tuning the downstream tasks. We argue that only taking single layer’s output restricts the power of pre-trained representation. Thus we deepen the representation learned by the model by fusing the hidden representation in terms of an explicit HIdden Representation Extractor (HIRE), which automatically absorbs the complementary representation with respect to the output from the final layer. Utilizing RoBERTa as the backbone encoder, our proposed improvement over the pre-trained models is shown effective on multiple natural language understanding tasks and help our model rival with the state-of-the-art models on the GLUE benchmark.

heading: 1 INTRODUCTION
text: Language representation is essential to the understanding of text. Recently, pre-trained language models based on Transformer (Vaswani et al., 2017) such as GPT (Radford et al., 2018), BERT (Devlin et al., 2019), XLNet (Yang et al., 2019), and RoBERTa (Liu et al., 2019c) have been shown to be effective for learning contextualized language representation. These models have since continued to achieve new state-of-the-art results on a variety of natural language processing tasks. They include question answering (Rajpurkar et al., 2018; Lai et al., 2017), natural language inference (Williams et al., 2018; Bowman et al., 2015), named entity recognition (Tjong Kim Sang & De Meulder, 2003), sentiment analysis (Socher et al., 2013) and semantic textual similarity (Cer et al., 2017; Dolan & Brockett, 2005).
Normally, Transformer-based models are pre-trained on large-scale unlabeled corpus in an unsupervised manner, and then fine-tuned on the downstream tasks through introducing task-specific output layer. When fine-tuning on the supervised downstream tasks, the models pass directly the output of Transformer encoder’s final layer, which is considered as the contextualized representation of input text, to the task-specific layer.
However, due to the numerous layers (i.e., Transformer blocks) and considerable depth of these pretrained models, we argue that the output of the last layer may not always be the best representation of the input text during the fine-tuning for downstream tasks. Devlin et al. (2019) shows diverse combinations of different layers’ outputs of the pre-trained BERT result in distinct performance on CoNLL-2003 Named Entity Recognition (NER) task (Tjong Kim Sang & De Meulder, 2003). Peters et al. (2018b) points out for pre-trained language models, including Transformer, the most transferable contextualized representations of input text tend to occur in the middle layers, while the top layers specialize for language modeling. Therefore, the onefold use of the last layer’s output may restrict the power of the pre-trained representation.
In this paper, we propose an extra network component design for Transformer-based model, which is capable of adaptively leveraging the hidden information in the Transformer’s hidden layers to refine the language representation. Our introduced additional components include two main additional components:
1. HIdden Representation Extractor (HIRE) dynamically learns a complementary representation which contains the information that the final layer’s output fails to capture.
2. Fusion network integrates the hidden information extracted by the HIRE with Transformer final layer’s output through two steps of functionalities, leading to a refined contextualized language representation.
Taking advantage of the robustness of RoBERTa by using it as our backbone Transformer-based encoder (Liu et al., 2019c), we conduct experiments on GLUE benchmark (Wang et al., 2018), which consists of nine Natural Language Understanding (NLU) tasks. With the help of HIRE, our model outperforms the baseline on 5/9 of them and advances the state-of-the-art on SST-2 dataset. Keeping the backbone Transformer model unchanged on its architecture, pre-training procedure and training objectives, we get comparable performance with other state-of-the-art models on the GLUE leaderboard, which verifies the effectiveness of the proposed HIRE enhancement over Transformer model.
2 MODEL

heading: 2.1 TRANSFORMER-BASED ENCODER
text: Transformer-based encoder is responsible for encoding input text into contextualized representation. Let {w1, . . . , wn} represent a sequence of nwords of input text, Transformer-based encoder encodes the input sequence into its universal contextualized representationR ∈ Rn×d:
R = Encoder({w1, . . . , wn}) (1) where d is the hidden size of the encoder and R is the output of Transformer-based encoder’s last layer which has the same length as the input text. We call it preliminary representation in this paper to distinguish it with the one that we introduce in section 2.2. Here, we omit a rather extensive formulations of Transformer and refer readers to Vaswani et al. (2017), Radford et al. (2018) and Devlin et al. (2019) for more details.

heading: 2.2 HIDDEN REPRESENTATION EXTRACTOR
text: Transformer-based encoder normally has many structure-identical layers stacked together, for example, BERTLARGE and XLNetLARGE all contain 24 layers of the identical structure, either outputs
from these hidden layers or the last layer, but not only limited to the latter, may be extremely helpful for specific downstream task. To make full use of the representations from these hidden layers, we introduce an extra component attached to the original encoder, HIdden Representation Extractor (HIRE) to capture the complementary information that the output of the last layer fails to capture. Since each layer does not take the same importance to represent a certain input sequence for different downstream tasks, we design an adaptive mechanism that can compute the importance dynamically. We measure the importance by an importance score.
The input to the HIRE is {H0, . . . ,Hj , . . . ,Hl} where l represents the number of layers in the encoder. Here H0 is the initial embedding of input text, which is the input of the encoder’s first layer but is updated during training and Hj ∈ Rn×d is the hidden-state of the encoder at the output of layer j. For the sake of simplicity, we call them all hidden-state afterwards.
We use the same 2-layer Bidirectional Gated Recurrent Unit (GRU) (Cho et al., 2014) to summarize each hidden-state of the encoder. Instead of taking the whole output of GRU as the representation of the hidden state, we concatenate GRU’s each layer and each direction’s final state together. In this way, we manage to summarize the hidden-state into a fixed-sized vector. Hence, we obtain U ∈ R(l+1)×4d with ui the summarized vector ofHi:
ui = Bi-GRU(Hi) ∈ R4d (2) where 0 ≤ i ≤ l. Then the importance value αi for hidden-stateHi is calculated by:
αi = ReLU(W Tui + b) ∈ R (3) whereW ∈ R4d×1 and b ∈ R are trainable parameters. Letα={αi} be normalized into a probability distribution s through a softmax layer:
s = softmax(α) ∈ Rl+1 (4) where si is the normalized weight of hidden-state i when computing the representation. Subsequently, we obtain the input sequence’s new representationA by:
A = l+1∑ i=0 siHi ∈ Rn×d (5)
With the same shape as the output of Transformer-based encoder’s final layer, HIRE’s output A is expected to contain the additional useful information from the encoder’s hidden-states and we call it complementary representation.

heading: 2.3 FUSION NETWORK
text: This module fuses the information contained in the output of Transformer-based encoder and the one extracted from encoders’ hidden states by HIRE.
Given the preliminary representation R, instead of letting it flow directly into task-specfic output layer, we combine it together with the complementary representationA to yieldM , defined by:
M = [R;A;R+A;R ◦A] ∈ Rn×4d (6) where ◦ is element-wise multiplication (Hadamard Product) and [; ] is concatenation across the last dimension.
Later, two-layer bidirectional GRU, with the output size of d for each direction, is used to fully fuse the information contained in the preliminary representation and the complementary representation. We concatenate the outputs of the GRUs in two dimensions together for the final contextualized representation:
F = Bi-GRU(M) ∈ Rn×2d (7)

heading: 2.4 OUTPUT LAYER
text: The output layer is task-specific. The following are the concerned implementation details on two tasks, classification and regression.
For classification task, given the input text’s contextualized representation F , following Devlin et al. (2019), we take the first row c ∈ R2d of F corresponding to the first input token (< s >) as the aggregated representation. Let m be the number of labels in the datasets, we pass c through a feed-forward network (FFN):
q =W T2 · tanh(W T1 c+ b1) + b2 ∈ Rm (8) with W1 ∈ R2d×d, W2 ∈ Rd×m, b1 ∈ Rd and b2 ∈ Rm the only parameters that we introduce in output layer. Finally, the probability distribution of predicted label is computed as:
p = softmax(q) ∈ Rm (9) For regression task, we obtain q in the same manner with m = 1, and take q as the predicted value.

heading: 2.5 TRAINING
text: For classification task, the training loss to be minimized is defined by the Cross-Entropy:
L(θ) = − 1 T T∑ i=1 log(pi,c) (10)
where θ is the set of all parameters in the model, T is the number of examples in the dataset, pi,c is the predicted probability of gold class c for example i .
For regression task, we define the training loss by mean squared error (MSE):
L(θ) = 1
T T∑ i=1 (qi − yi)2 (11)
where qi is the predicted value for example i and yi is the ground truth value for example i.

heading: 3 EXPERIMENTS

heading: 3.1 DATASET
text: We conducted the experiments on the General Language Understanding Evaluation (GLUE) benchmark (Wang et al., 2018) to evaluate our proposed method. GLUE is a collection of 9 diverse datasets1 for training, evaluating, and analyzing natural language understanding models.

heading: 3.2 MAIN RESULTS
text: 1All the datasets can be obtained from https://gluebenchmark.com/tasks
Table 1 compares our method with a list of Transformer-based models on the development set. Model parameter comparison is shown in Table 2. To obtain a direct and fair comparison with our baseline model RoBERTa, following the original paper (Liu et al., 2019c), we fine-tune RoBERTa+HIRE separately for each of the GLUE tasks, using only task-specific training data. The single-model results for each task are reported. We run our model with five different random seeds but the same hyperparameters and take the median value. Due to the problematic nature of WNLI dataset, we exclude its results in this table. The results shows that RoBERTa+HIRE consistently outperforms RoBERTa on 4 of the GLUE task development sets, with an improvement of 1.7 points, 0.4 points, 0.5/0.2 points, 0.3 points on CoLA, SST-2, MNLI and QNLI respectively. And on the MRPC, STS-B and RTE task, our model get the same result as RoBERTa. It should be noted that the improvement is entirely attributed to the introduction of HIdden Representation Extractor and fusion network in our model.
Table 3 presents the results of HIRE enhancement and other models on the test set that have been submitted to the GLUE leaderboard. Following Liu et al. (2019c), we fine-tune STS-B and MRPC starting from the MNLI single-task model. Given the simplicity between RTE, WNLI and MNLI, and the large-scale nature of MNLI dataset (393k), we also initialize RoBERTa+HIRE with the weights of MNLI single-task model before fine-tuning on RTE and WNLI. We submitted the ensemble-model results to the leaderboard. The results show that RoBERTa+HIRE still boosts the strong RoBERTa baseline model on the test set. To be specific, RoBERTa+HIRE outperforms RoBERTa over CoLA, SST-2, MRPC, SST-B, MNLI-mm and QNLI with an improvement of 0.8 points, 0.4 points, 0.7/0.9 points, 0.2/0.1 points, 0.2 points and 0.1 points respectively. In the meantime, RoBERTa+HIRE gets the same results as RoBERTa on QQP and WNLI. By category, RoBERTa+HIRE has better performance than RoBERTa on the single sentence tasks, similarity and paraphrase tasks. It is worth noting that our model obtains state-of-the-art results on SST-2 dataset, with a score of 97.1. The results are quite promising since HIRE does not modify the encoder internal architecture (Yang et al., 2019) or redefine the pre-training procedure (Liu et al., 2019c) , getting the comparable results with them.

heading: 4 ABLATION STUDY
text: In this section, we perform a set of ablation experiments to understand the effects of our proposed techniques during fine-tuning. All the results reported in this section are a median of five random runs.

heading: 4.1 MODEL DESIGN CONSIDERATION
text: To individually evaluate the importance of HIRE and fusion network, we vary our model in the following ways and conduct the experiments on the development set of CoLA and STS-B. The results are in Table 4:
• We remove the HIRE from our model and pass the preliminary representation R directly into the fusion network. In order to keep the fusion network, we fuse the preliminary representation with itself, which means we define insteadM by:
M = [R;R;R+R;R ◦R] ∈ Rn×4d (12) The results are presented in row 2.
• We remove the fusion network, and take the outputs of HIRE as the final representation of the input and flow it directly into the output layer and present the results in row 3.
As can be seen from the table, to use of HIRE to extract the hidden information is crucial to the model: Matthews correlation of CoLA and Pearson correlation coefficient of STS-B drop dramatically by 1.2 and 0.9 points if it’s removed. We also observe that fusion network is an important component that contributes 1.5/0.2 gains on the CoLA and STS-B tasks. The results are aligned with our assumption that HIRE extracts the complementary information from the hidden layers while the fusion network fuses it with the preliminary representation.

heading: 4.2 EFFECT OF DYNAMIC MECHANISM
text: We investigate how the adaptive assignment mechanism of the importance score affects the model’s performance. CoLA is chosen as the downstream task. Table 5 compares our proposed mechanism
with diverse fixed combinations of importance scores over different range of layers: first 6, last 6 or all 25 layers. Two strategies are studied: mean and random. In the mean situation, we suppose all the layers contribute exactly the same. On the contrary, under the random condition, we generate a score for each layer randomly and do the SoftMax operation across all the layers.
From the table, we observe that fixing each layer’s importance score for all examples hurts the model performance. Across all rows, we find that none of single strategy can yield the best performance. The results enable us to conclude that the hidden-state weighting mechanism introduced by HIRE may indeed adapt to diverse downstream tasks for better performance.

heading: 4.3 EFFECT OF GRU LAYER NUMBER IN FUSION NETWORK
text: To investigate the effect of GRU layer number in the fusion network, we set the GRU layer number from 0 to 3 and conduct the ablation experiments on the development dataset of CoLA. Table 6 shows the results. We observe that the modest number 2 would be a better choice.

heading: 5 ANALYSIS
text: We compare the importance score’s distribution of different NLU tasks. For each task, we run our best single model over the development set and the results are calculated by averaging the values across all the examples within each dataset. The results are presented in the left of Figure 2. From the top to the bottom of the heatmap, the results are placed in the following order: single-sentence tasks, similarity and paraphrase tasks, and natural language inference tasks. From it, we find that the distribution differs among the different tasks, which demonstrates HIRE’s dynamic ability to adapt for distinct tasks when computing the complimentary representation. The most important contribution occurs below the final layer for all the tasks except STS-B and RTE. All layers have a close contribution for STS-B and RTE task. In addition, we find that QNLI, a classification task which requires the model to determine whether the context sentence contains the answer to the question, relies on layers 2-4 to some extent. In fact, Jawahar et al. (2019) state that BERT mostly captures phrase-level (or span-level) information in the lower layers and that this information gets gradually diluted in higher layers. Since QNLI is derived from the span extraction question answering dataset
SQuAD, where the answer is a span of the input text, we speculate that HIRE takes advantage of this information when making the prediction.
The right of Figure 2 presents the distribution of importance scores over different layers for each example of SST-2 dataset. The number on the ordinate axis denotes the index of the example. It shows that HIRE can adapt not only distinct tasks but also the different examples. In the meantime, we observe also that even though there are subtle differences among these examples, they follow certain same patterns when calculating the complementary representation, for example, layers 21 and 22 contribute the most for almost all the examples and also the layers around them. But the figure shows also that for some examples, all layers contribute nearly equally.

heading: 6 RELATED WORK
text: Transformer model is empowered by self-attention mechanism and has been applied as an effective model architecture design in quite a lot of pre-trained language models (Vaswani et al., 2017). OpenAI GPT (Radford et al., 2018) is the first model that introduced Transformer architecture into unsupervised pre-training. But instead of unidirectional training like GPT, BERT (Devlin et al., 2019) adopts Masked LM objective when pre-training, which enables the representation to incorporate context from both direction. The next sentence prediction (NSP) objective is also used by BERT to better model the relationship between sentences. Trained with dynamic masking, large mini-batches and a larger byte-level BPE, full-sentences without NSP, RoBERTa (Liu et al., 2019c) improves BERT’s performance on the downstream tasks from a better BERT re-implementation training on BooksCorpus(Zhu et al., 2015), CC-News, Openwebtext and Stories. In terms of finetuning on downstream tasks, all these powerful Transformer-based models help various NLP tasks continuously achieve new state-of-the-art results. Diverse new methods have been proposed recently for fine-tuning the downstream tasks, including multi-task learning (Liu et al., 2019b), adversarial training (Zhu et al., 2020) or incorporating semantic information into language representation (Zhang et al., 2020).
Traditionally, downstream tasks or back-end part of models take representations from the last layer of the pre-trained language models as the default input. However, recent studies trigger researchers’ interest on the intermediate layers’ representation learned by pre-trained models. When studying the linguistic knowledge and transferability of contextualized word representations with a series of seventeen diverse probing tasks, Liu et al. (2019a) observe that Transformers tend to encode transferable features in their intermediate layers, aligned with the results by Peters et al. (2018b). Jawahar et al. (2019) show a rich hierarchy of linguistic information is encoded by BERT, with surface features, syntactic features and semantic features lying from bottom to top in the layers. So far, to our best knowledge, exploiting the representations learned by hidden layers is still stuck with limited empirical observations, which motivates us to propose a general solution for fully exploiting all levels of representations learned by the pre-trained language models. However, we want to note that a freezing/fine-tuning discrepancy may exist, since previous observations are made by adopting a feature extracting approach while our work is conducted in the fine-tuning scenario.
Several works have made attempts to utilize the information from the intermediate layers of deep models (Zhao et al., 2015; Peters et al., 2018a; Zhu et al., 2018; Tenney et al., 2019). Peters et al. (2018a) propose a deep contextualized word representation called ELMo, which is a task-specific linear combination of the intermediate layer representations in the bidirectional LSTM language model. Tenney et al. (2019) find that using ELMo-style scalar mixing of layer activations, both deep Transformer models (BERT and GPT) gain a significant performance improvement on a novel edge probing task. Zhu et al. (2018) adopt a linear combination of embeddings from different layers in BERT to encode tokens for conversational question answering but in a feature-based way. Compared with these works, our approach still presents the following innovations: 1) Our dynamic layer weighting mechanism calculates importance scores for each example over different layers, which is distinct from previous works (e.g., ELMo), where the contribution score (in the form of a parameter) for each layer is always same for all the examples of the same task. 2) Our approach fuses the representation weighted from the hidden layers and the one from the last layer to get a refined representation. 3) To our best knowledge, our work is the first one that takes advantage of the pre-trained language model’s intermediate information in the context of fine-tuning.

heading: 7 CONCLUSION
text: This paper presents HIdden Representation Extractor (HIRE), a novel enhancement component that refines language representation by adaptively leveraging the Transformer-based model’s hidden layers. In our proposed model design, HIRE dynamically generates complementary representation from all hidden layers other than that from the default last layer. A lite fusion network then incorporates the outputs of HIRE into those of the original model. The experimental results demonstrate the effectiveness of refined language representation for natural language understanding. The analysis highlights the distinct contribution of each layer’s output for diverse tasks and different examples.

heading: A APPENDIX
text: A.1 DETAILED DESCRIPTIONS FOR THE GLUE BENCHMARK
Three different tasks are presented in GLUE benchmark (Wang et al., 2018) according to the original paper:
Single-sentence tasks: The Corpus of Linguistic Acceptability (CoLA) (Warstadt et al., 2018) requires the model to determine whether a sentence is grammatically acceptable; the Stanford Sentiment Treebank (SST-2) (Socher et al., 2013) is to predict the sentiment of movie reviews with label of positive or negative.
Similarity and paraphrase tasks: Similarity and paraphrase tasks are to predict whether each pair of sentences captures a paraphrase/semantic equivalence relationship. The Microsoft Research Paraphrase Corpus (MRPC) (Dolan & Brockett, 2005), the Quora Question Pairs (QQP) 2 and the Semantic Textual Similarity Benchmark (STS-B) (Cer et al., 2017) are presented in this category.
Natural Language Inference (NLI) tasks: Natural language inference is the task of determining whether a “hypothesis” is true (entailment), false (contradiction), or undetermined (neutral) given a “premise”. GLUE benchmark contains the following tasks: the Multi-Genre Natural Language Inference Corpus (MNLI) (Williams et al., 2018), the converted version of the Stanford Question Answering Dataset (QNLI) (Rajpurkar et al., 2016), the Recognizing Textual Entailment (RTE) (Dagan et al., 2006; Roy et al., 2006; Giampiccolo et al., 2007; Bentivogli et al., 2009) and the Winograd Schema Challenge (WNLI) (Levesque et al., 2012).
Four official metrics are adopted to evaluate the model performance: Matthews correlation (Matthews, 1975), accuracy, F1 score, Pearson and Spearman correlation coefficients.
A.2 IMPLEMENTATION DETAILS
Our implementation of HIRE and its related fusion network is based on the PyTorch implementation of Transformer 3.
Preprocessing: Following Liu et al. (2019c), we adopt GPT-2 (Radford et al., 2019) tokenizer with a Byte-Pair Encoding (BPE) vocabulary of subword units size 50K. The maximum length of input sequence is 128 tokens.
Model configurations: We use RoBERTaLARGE as the Transformer-based encoder and load the pretraining weights of RoBERTa (Liu et al., 2019c). Like BERTLARGE, RoBERTaLARGE model contains 24 Transformer-blocks, with the hidden size being 1024 and the number of self-attention heads being 16 (Liu et al., 2019c; Devlin et al., 2019).
Optimization: We use Adam optimizer (Kingma & Ba, 2015) with β1 = 0.9, β2 = 0.98 and = 10−6 and the learning rate is selected amongst {1e-5, 2e-5} with a warmup rate of 0.06 depending on the nature of the task. The number of training epochs ranges from 3 to 27 with the early stop and the batch size is selected amongst {16, 32, 48}. In addition to that, we clip the gradient norm within 1 to prevent exploding gradients problem occurring in the recurrent neural networks in our model.
Regularization: We employ two types of regularization methods during training. We apply dropout (Srivastava et al., 2014) of rate 0.1 to all layers in the Transformer-based encoder and GRUs in the HIRE and fusion network. We additionally adopt L2 weight decay of 0.1 during training.
2https://www.quora.com/q/quoradata/First-Quora-Dataset-Release-Question-Pairs 3https://github.com/huggingface/transformers

Review summaries:
This paper presents a new mechanism, called HIRE, to extract more information from the intermediate layers of pre-trained models, which will be further fused with the last layer of pre-trained models. The main contribution of this work is the newly proposed dynamic feature extractor HIRE and the fusion network. Experiments confirmed the effectiveness of the proposed method, and some interesting observations on the importance of different layers for different tasks were given (i.e. Figure 2). 

The paper proposes a method to improve the downstream performance of a pretrained Transformer on NLP tasks. The core idea is to not only use the output of the last Transformer layer for prediction, but let the model decide how to fuse the information from intermediate layers as well. To dynamically decide which intermediate layers to use depending on the input example, the model uses a mechanism conceptually similar to self-attention, which yields a normalized importance score for each layer. The importance-weighted sum then yields a complementary representation to the last layer. Lastly, another network produces a final, integrated representation from the output at the last layer and the complementary representation, which is then used for prediction.