Investigating Meta-Learning Algorithms for Low-Resource Natural Language Understanding Tasks

Zi-Yi Dou, Keyi Yu, Antonios Anastasopoulos

Introduction

With the ability to learn rich distributed representations of data in an end-to-end fashion, deep neural networks have achieved the state of the arts in a variety of fields He et al. (2017); Vaswani et al. (2017); Povey et al. (2018); Yu et al. (2018). For natural language understanding (NLU) tasks, robust and flexible language representations can be adapted to new tasks or domains efficiently. Aiming at learning representations that are not exclusively tailored to any specific tasks or domains, researchers have proposed several ways to learn general language representations.

Recently, there is a trend of learning universal language representations via language model pre-training Dai and Le (2015); Peters et al. (2018); Radford et al. (2018). In particular, Devlin et al. (2019) present the BERT model which is based on a bidirectional Transformer Vaswani et al. (2017). BERT is pre-trained with both masked language model and next sentence prediction objectives and exhibits strong performance on several benchmarks, attracting huge attention from researchers. Another line of research tries to apply multi-task learning to representation learning Liu et al. (2015); Luong et al. (2015). Multi-task learning allows the model to leverage supervision signals from related tasks and prevents the model from overfitting to a single task. By combining the strengths of both language model pre-training and multi-task learning, Liu et al. (2019b) improve the BERT model with multi-task learning and their proposed MT-DNN model successfully achieves state-of-the-art results on several NLU tasks.

Although multi-task learning can achieve promising performance, there still exist some potential problems. As shown in Figure 1, multi-task learning may favor tasks with significantly larger amounts of data than others. Liu et al. (2019b) alleviate this problem by adding an additional fine-tuning stage after multi-task learning. In this paper, we propose to apply meta-learning algorithms in general language representations learning. Meta-learning algorithms aim at learning good initializations that can be useful for fine-tuning on various tasks with minimal training data, which makes them appealing alternatives to multi-task learning. Specifically, we investigate the recently proposed model-agnostic meta-learning algorithm (MAML) Finn et al. (2017) and its variants, namely first-order MAML and Reptile Nichol et al. (2018), for NLU tasks.

We evaluate the effectiveness and generalization ability of the proposed approaches on the General Language Understanding Evaluation (GLUE) benchmark Wang et al. (2019). Experimental results demonstrate that our approaches successfully outperform strong baseline models on the four low-resource tasks. In addition, we test generalization capacity of the models by fine-tuning them on a new task, and the results reveal that the representations learned by our models can be adapted to new tasks more effectively compared with baseline models.

Proposed Approaches

In this section, we first briefly introduce some key ideas of meta learning, and then illustrate how we apply meta-learning algorithms in language representations learning.

Meta-learning, or learning-to-learn, has recently attracted researchers’ interests in the machine learning community Lake et al. (2015). The goal of meta-learning algorithms is to allow fast adaptation on new training data. In this paper, we mainly focus on optimization-based meta-learning algorithms, which achieve the goal by adjusting the optimization algorithm. Specifically, we investigate MAML, one of the most representative algorithms in this category, and its variants for NLU tasks.

MAML and its variants offer a way to learn from a distribution of tasks and adapt to target tasks using few samples. Formally, given a set of tasks {T1,⋯ ,Tk}\{T_{1},\cdots,T_{k}\}, the process of learning model parameters θ\theta can be understood as Gu et al. (2018):

Hopefully, by exposing models to a variety of tasks, the models can learn new tasks with few steps and minimal amounts of data.

2 General Framework

In this part, we introduce the general framework of the MAML approach and its variants, including first-order MAML and Reptile.

We first describe the meta-learning stage. Suppose we are given a model fθf_{\theta} with parameters θ\theta and a task distribution p(T)p(T) over a set of tasks {T1,T2,⋯ ,Tk}\{T_{1},T_{2},\cdots,T_{k}\}, at each step during the meta-learning stage, we first sample a batch of tasks {Ti}∼p(T)\{T_{i}\}\sim p(T), and then update the model parameters by kk (k≥1)(k\geq 1) gradient descent steps for each task TiT_{i} according to the equation:

where LiL_{i} is the loss function for TiT_{i} and α\alpha is a hyper-parameter.

The model parameters θ\theta are then updated by:

We would illustrate the MetaUpdate step in the following part. It should be noted that the data used for the MetaUpdate step (Eqn. 2) is different from that used for the first kk gradient descent steps (Eqn. 1).

The overall training procedure is shown in Algorithm 1. Basically, the algorithm consists of three stages: the pre-training stage as in BERT, the meta-learning stage and the fine-tuning stage.

3 The MetaUpdate Step

As demonstrated in the previous paragraph, MetaUpdate is an important step in the meta-learning stage. In this paper, we investigate three ways to perform MetaUpdate as described in the following parts.

The vanilla MAML algorithm Finn et al. (2017) updates the model with the meta-objective function:

Therefore, MAML would implement the MetaUpdate step by updating θ\theta according to:

First-Order MAML

Suppose θ(k)\theta^{(k)} is obtained by performing kk inner gradient steps starting from the initial parameter θ(0)\theta^{(0)}, we can deduce that:

Therefore, MAML requires calculating second derivatives, which can be both computationally and memory intensive. First-Order MAML (FOMAML) ignores the second derivative part and implement the MetaUpdate as:

Reptile

Reptile Nichol et al. (2018) is another first-order gradient-based meta-learning algorithm that is similar to joint training, as it implements the MetaUpdate step as:

Basically, Reptile moves the model weights towards new parameters obtained by multiple gradient descent steps. Despite the simplicity of Reptile, it has been demonstrated to achieve competitive or superior performance compared to MAML.

4 Choosing the Task Distributions

We experiment with three different choices of the task distribution p(T)p(T). Specifically, we propose the following options:

Probability Proportional to Size (PPS): the probability of selecting a task is proportional to the size of its dataset.

Mixed: at each epoch, we first sample tasks uniformly and then exclusively select the target task.

Experiments

We conduct experiments on the GLUE dataset Wang et al. (2019) and only on English. Following previous work Devlin et al. (2019); Liu et al. (2019b) we do not train or test models on the WNLI dataset Levesque et al. (2012). We treat the four high-resource tasks, namely SST-2 Socher et al. (2013), QQP,data.quora.com/First-Quora-DatasetRelease-Question-Pairs MNLI Williams et al. (2018), and QNLI Rajpurkar et al. (2016), as auxiliary tasks. The other four tasks, namely CoLA Warstadt et al. (2018), MRPC Dolan and Brockett (2005), STS-B Cera et al. (2017), and RTE Dagan et al. (2005) are our target tasks. We also evaluate the generalization ability of our approaches on the SciTail dataset Khot et al. (2018). The details of all datasets are illustrated in Appendix A.

We compare our models with two strong baselines: the BERT model Devlin et al. (2019) and the MT-DNN model Liu et al. (2019b). While the former pre-trains the Transformer model on large amounts of unlabeled dataset, the latter further improves it with multi-task learning.

For BERT and MT-DNN, we use their publicly available code to obtain the final results. The setting of MT-DNN is slightly different from the setting of BERT in terms of optimizer choices. We implement our algorithms upon the BERTBASE{}_{\text{\bf BASE}} model.BERTBASE{}_{\text{\bf BASE}} and BERTLARGE{}_{\text{\bf LARGE}} differ at the number of hidden layers (12 vs. 24), hidden size (768 vs. 1024) and the number of attention heads (12 vs. 16). We use the Adam optimizer Kingma and Ba (2015) with a batch size of 32 and learning rates of 5e-5 to train the models for 5 epochs in the meta-learning stage. We set the update step kk to 5, the number of sampled tasks in each step to 8 and α\alpha to 1e-3.

We first use the three meta-learning algorithms with PPS sampling and present in Table 1 the experimental results on the GLUE test set. Generally, the meta-learning algorithms achieve better performance than the strong baseline models, with Reptile performing the best.

Since the MT-DNN also uses PPS sampling, the improvements suggest meta-learning algorithms can indeed learn better representations compared with multi-task learning. Reptile outperforming MAML indicates that reptile is a more effective and efficient algorithm compared with MAML in our setting.

2 Ablation Studies

As we have mentioned above, we propose three different choices of the task distribution p(T)p(T) in this paper. Here we train Reptile with these task distributions and test models’ performance on the development set as shown in Table 2.

For uniform sampling, we set the number of training steps equal to that of the PPS method. For mixed sampling, we try mix ratios of both 2:1 and 5:1. The results demonstrate that Reptile with PPS sampling achieves the best performance, which suggests that larger amounts of auxiliary task data can generally lead to better performance.

Effect of Hyperparameters for Meta-Gradients

In this part, we test the effect of the number of update steps kk and the learning rate in the inner learning loop. The experimental results on the development sets are shown in Table 3. We find that setting kk to 5 is the optimal strategy and more or fewer update steps may lead to worse performance.

Smaller kk would make the algorithms similar to joint training as joint training is an extreme case of Reptile where k=1k=1, and thus cause the model to lose the advantage of using meta-learning algorithms. Similarly, Larger kk can make the resulting gradients deviate from the normal ones and become uninformative.

We also vary the inner learning rate α\alpha and investigate its impact. The results are listed in Table 3. We can see that larger α\alpha may degrade the performance because the resulting gradients deviate a lot from normal ones. The above two ablations studies demonstrate the importance of making the meta-gradient informative.

3 Transferring to New Tasks

In this part, we test whether our learned representations can be adapted to new tasks efficiently. To this end, we perform transfer learning experiments on a new natural language inference dataset, namely SciTail.

We randomly sample 0.1%, 1%, 10% and 100% of the training data and test models’ performance on these datasets. Figure 2 reveals that our model consistently outperforms the strong MT-DNN baseline across different settings, indicating the learned representations are more effective for transfer learning. In particular, the algorithm is more effective when less data are available, especially compared to BERT, suggesting the meta-learning algorithms can indeed be helpful for low-resource tasks.

Related Work

There is a long history of learning general language representations. Previous work on learning general language representations focus on learning word Mikolov et al. (2013); Pennington et al. (2014) or sentence representations Le and Mikolov (2014); Kiros et al. (2015) that are helpful for downstream tasks. Recently, there is a trend of learning contextualized word embeddings Dai and Le (2015); McCann et al. (2017); Peters et al. (2018); Howard and Ruder (2018). One representative approach is the BERT model Devlin et al. (2019) which learns contextualized word embeddings via bidirectional Transformer models.

Another line of research on learning representations focus on multi-task learning Collobert et al. (2011); Liu et al. (2015). In particular, Liu et al. (2019b) propose to combine multi-task learning with language model pre-training and demonstrate the two methods are complementary to each other.

Meta-learning algorithms have received lots of attention recently due to their effectiveness Finn et al. (2017); Fan et al. (2018). However, the potential of applying meta-learning algorithms in NLU tasks have not been fully investigated yet. Gu et al. (2018) have tried to apply first-order MAML in machine translation and Qian and Yu (2019) propose to address the domain adaptation problem in dialogue generation by using MAML. To the best of our knowledge, the Reptile algorithm, which is simpler than MAML and potentially more useful, has been given less attention.

Conclusion

In this paper, we investigate three optimization-based meta-learning algorithms for low-resource NLU tasks. We demonstrate the effectiveness of these algorithms and perform a fair amount of ablation studies. We also show the learned representations can be adapted to new tasks effectively. Our study suggests promising applications of meta-learning algorithms in the field of NLU. Future directions include integrating more sophisticated training strategies of meta-learning algorithms as well as validating our algorithms on other datasets.

Acknowledgements

The authors are grateful to the anonymous reviewers for their constructive comments, and to Graham Neubig and Junxian He for helpful discussions. This material is based upon work generously supported partly by the National Science Foundation under grant 1761548.

References

Appendix A The GLUE and SciTail Datasets

Basically, the GLUE dataset Wang et al. (2019) consists of three types of tasks: single-sentence classification, similarity and paraphrase tasks, and inference tasks, as shown in Table 4.

The model needs to make a prediction given a single sentence for this type of tasks. The goal of the CoLA task is to predict whether an English sentence is grammatically plausible and the goal of the SST-2 task is to determine whether the sentiment of a sentence is positive or negative.

Similarity and Paraphrase Tasks.

For this type of tasks, the model needs to determine whether or to what extent two given sentences are semantically similar to each other. Both the MRPC and the QQP tasks are classification tasks that require the model to predict whether the sentences in a pair are semantically equivalent. The STS-B task, on the other hand, is a regression task and requires the model to output a real-value score representing the semantic similarity of the two sentences.

Inference Tasks.

Both the RTE and the MNLI tasks aim at predicting whether a sentence is entailment, contradiction or neutral with respect to the other. QNLI is converted from a question answering dataset, and the task is to determine whether the context sentence contains the answer to the question. WNLI is to predict if the sentence with the pronoun substituted is entailed by the original sentence. Because the test set is imbalanced and the development set is adversarial, so far none of the proposed models could surpass the performance of the simple majority voting strategy. Therefore, we do not use the WNLI dataset in this paper.

SciTail is a textual entailment dataset that is derived from a science question answering dataset Khot et al. (2018). Given a premise and a hypothesis, the model need to determine whether the premise entails the hypothesis. The dataset is fairly difficult as the sentences are linguistically challenging and the lexical similarity of premise and hypothesis is high.

Appendix B Implementation Details

Our implementation is based on the PyTorch implementation of BERT.https://github.com/huggingface/pytorch-pretrained-BERT We first load the pre-trained BERTBASE{}_{\text{\bf BASE}} model. We use the Adam optimizer Kingma and Ba (2015) with a batch size of 32 for both meta-learning and fine-tuning. We set the maximum length to 80 to reduce GPU memory usages.

In the meta-learning stage, we use a learning rate of 5e-5 to train the models for 5 epochs. Both the dropout and the warm-up ratio are set to 0.1 and we do not use gradient clipping. We set the update step kk to 5, the number of sampled tasks in each step to 8 and α\alpha to 1e-3.

For fine-tuning, again the dropout and warum-up ratio are set to 0.1 and we do not use gradient clipping. The learning rate is selected from {5e-6, 1e-5, 2e-5, 5e-5} and the number of epochs is selected from {3, 5, 10, 20}. We select hyper-parameters that achieve the best performance on the development set.

We do not use the stochastic answer network as in MT-DNN for efficiency.

Appendix C Linguistic Information

In this part, we use 10 probing tasks Conneau et al. (2018) to study what linguistic information is captured by each layer of the models.

A probing task is a classification problem that requires the model to make predictions related to certain linguistic properties of sentences. The abbreviations for the 10 tasks are listed in Table 5. Basically, these tasks are set to test the model’s abilities to capture surface, syntactic or semantic information. We refer the reader to Conneau et al. (2018) for details. We freeze all the parameters of the models and only train the classification layer for the probing tasks.

First, we can see that the BERT model captures more surface, syntactic and semantic information than other models, suggesting it learns more general representations. MT-DNN and our models, on the other hand, learn representations that are more tailored to the GLUE tasks.

Second, our models perform better than MT-DNN on the probing tasks, indicating meta-learning algorithms may find a balance between general linguistic information and task-specific information. Among the three meta-learning algorithms, Reptile can capture more general linguistic information than others. Considering Reptile has outperformed the other two models on the GLUE dataset, these results further demonstrate Reptile may be more suitable for NLU tasks.

Third, we find that there may not always exist a monotonic trend on what linguistic information each layer captures. Also, contrary to the findings from Liu et al. (2019a) which suggest the middle layers of BERT are more transferable and contain more syntactic and semantic information, our experimental results demonstrate that this may not always be true. We conjecture this is because both syntactic and semantic information are broad concepts and the probing tasks in Liu et al. (2019a) may not cover all of them. For example, there exist a monotonic trend for SOMO while the middle layers of these models are better at tasks like SubNum.

Another interesting thing to note is that the lower layers of models perform rather poorly on the word content task, which tests whether the model can recover information about the original words in the sentence. We attribute this phenomenon to the use of subwords and position/token embeddings. In the higher layers, the model may gain more word-level information through the self-attention mechanism.