Adversarial Multi-task Learning for Text Classification

Pengfei Liu, Xipeng Qiu, Xuanjing Huang

Introduction

Multi-task learning is an effective approach to improve the performance of a single task with the help of other related tasks. Recently, neural-based models for multi-task learning have become very popular, ranging from computer vision Misra et al. (2016); Zhang et al. (2014) to natural language processing Collobert and Weston (2008); Luong et al. (2015), since they provide a convenient way of combining information from multiple tasks.

However, most existing work on multi-task learning Liu et al. (2016c, b) attempts to divide the features of different tasks into private and shared spaces, merely based on whether parameters of some components should be shared. As shown in Figure 1-(a), the general shared-private model introduces two feature spaces for any task: one is used to store task-dependent features, the other is used to capture shared features. The major limitation of this framework is that the shared feature space could contain some unnecessary task-specific features, while some sharable features could also be mixed in private space, suffering from feature redundancy.

Taking the following two sentences as examples, which are extracted from two different sentiment classification tasks: Movie reviews and Baby products reviews.

The word “infantile” indicates negative sentiment in Movie task while it is neutral in Baby task. However, the general shared-private model could place the task-specific word “infantile” in a shared space, leaving potential hazards for other tasks. Additionally, the capacity of shared space could also be wasted by some unnecessary features.

To address this problem, in this paper we propose an adversarial multi-task framework, in which the shared and private feature spaces are inherently disjoint by introducing orthogonality constraints. Specifically, we design a generic shared-private learning framework to model the text sequence. To prevent the shared and private latent feature spaces from interfering with each other, we introduce two strategies: adversarial training and orthogonality constraints. The adversarial training is used to ensure that the shared feature space simply contains common and task-invariant information, while the orthogonality constraint is used to eliminate redundant features from the private and shared spaces.

The contributions of this paper can be summarized as follows.

Proposed model divides the task-specific and shared space in a more precise way, rather than roughly sharing parameters.

We extend the original binary adversarial training to multi-class, which not only enables multiple tasks to be jointly trained, but allows us to utilize unlabeled data.

We can condense the shared knowledge among multiple tasks into an off-the-shelf neural layer, which can be easily transferred to new tasks.

Recurrent Models for Text Classification

There are many neural sentence models, which can be used for text modelling, involving recurrent neural networks Sutskever et al. (2014); Chung et al. (2014); Liu et al. (2015a), convolutional neural networks Collobert et al. (2011); Kalchbrenner et al. (2014), and recursive neural networks Socher et al. (2013). Here we adopt recurrent neural network with long short-term memory (LSTM) due to their superior performance in various NLP tasks Liu et al. (2016a); Lin et al. (2017).

Long short-term memory network (LSTM) Hochreiter and Schmidhuber (1997) is a type of recurrent neural network (RNN) Elman (1990), and specifically addresses the issue of learning long-term dependencies. While there are numerous LSTM variants, here we use the LSTM architecture used by Jozefowicz et al. (2015), which is similar to the architecture of Graves (2013) but without peep-hole connections.

The LSTM is precisely specified as follows.

The update of each LSTM unit can be written precisely as follows:

Here, the function LSTM(,,,)\mathbf{LSTM}(\cdot,\cdot,\cdot,\cdot) is a shorthand for Eq. (1-3), and θp\theta_{p} represents all the parameters of LSTM.

Text Classification with LSTM

Given a text sequence x={x1,x2,,xT}x=\{x_{1},x_{2},\cdots,x_{T}\}, we first use a lookup layer to get the vector representation (embeddings) xi\mathbf{x}_{i} of the each word xix_{i}. The output at the last moment hT\mathbf{h}_{T} can be regarded as the representation of the whole sequence, which has a fully connected layer followed by a softmax non-linear layer that predicts the probability distribution over classes.

where y^{\hat{\mathbf{y}}} is prediction probabilities, W\mathbf{W} is the weight which needs to be learned, b\mathbf{b} is a bias term.

Given a corpus with NN training samples (xi,yi)(x_{i},y_{i}), the parameters of the network are trained to minimise the cross-entropy of the predicted and true distributions.

where yijy_{i}^{j} is the ground-truth label; y^ij{\hat{y}_{i}^{j}} is prediction probabilities, and CC is the class number.

Multi-task Learning for Text Classification

The goal of multi-task learning is to utilizes the correlation among these related tasks to improve classification by learning tasks in parallel. To facilitate this, we give some explanation for notations used in this paper. Formally, we refer to DkD_{k} as a dataset with NkN_{k} samples for task kk. Specifically,

where xikx_{i}^{k} and yiky_{i}^{k} denote a sentence and corresponding label for task kk.

The key factor of multi-task learning is the sharing scheme in latent feature space. In neural network based model, the latent features can be regarded as the states of hidden neurons. Specific to text classification, the latent features are the hidden states of LSTM at the end of a sentence. Therefore, the sharing schemes are different in how to group the shared features. Here, we first introduce two sharing schemes with multi-task learning: fully-shared scheme and shared-private scheme.

In fully-shared model, we use a single shared LSTM layer to extract features for all the tasks. For example, given two tasks mm and nn, it takes the view that the features of task mm can be totally shared by task nn and vice versa. This model ignores the fact that some features are task-dependent. Figure 2a illustrates the fully-shared model.

Shared-Private Model (SP-MTL)

As shown in Figure 2b, the shared-private model introduces two feature spaces for each task: one is used to store task-dependent features, the other is used to capture task-invariant features. Accordingly, we can see each task is assigned a private LSTM layer and shared LSTM layer. Formally, for any sentence in task kk, we can compute its shared representation stk\mathbf{s}_{t}^{k} and task-specific representation htk\mathbf{h}_{t}^{k} as follows:

where LSTM(.,θ)\mathbf{LSTM}(.,\theta) is defined as Eq. (4).

The final features are concatenation of the features from private space and shared space.

2 Task-Specific Output Layer

For a sentence in task kk, its feature h(k)\mathbf{h}^{(k)}, emitted by the deep muti-task architectures, is ultimately fed into the corresponding task-specific softmax layer for classification or other tasks.

The parameters of the network are trained to minimise the cross-entropy of the predicted and true distributions on all the tasks. The loss LtaskL_{task} can be computed as:

where αk\alpha_{k} is the weights for each task kk respectively. L(y^,y)L({\hat{y}},y) is defined as Eq. 6.

Incorporating Adversarial Training

Although the shared-private model separates the feature space into the shared and private spaces, there is no guarantee that sharable features can not exist in private feature space, or vice versa. Thus, some useful sharable features could be ignored in shared-private model, and the shared feature space is also vulnerable to contamination by some task-specific information.

Therefore, a simple principle can be applied into multi-task learning that a good shared feature space should contain more common information and no task-specific information. To address this problem, we introduce adversarial training into multi-task framework as shown in Figure 3 (ASP-MTL).

Adversarial networks have recently surfaced and are first used for generative model Goodfellow et al. (2014). The goal is to learn a generative distribution pG(x)p_{G}(x) that matches the real data distribution Pdata(x)P_{data}(x) Specifically, GAN learns a generative network G and discriminative model D, in which G generates samples from the generator distribution pG(x)p_{G}(x). and D learns to determine whether a sample is from pG(x)p_{G}(x) or Pdata(x)P_{data}(x). This min-max game can be optimized by the following risk:

While originally proposed for generating random samples, adversarial network can be used as a general tool to measure equivalence between distributions Taigman et al. (2016). Formally, Ajakan et al. (2014) linked the adversarial loss to the HH-divergence between two distributions and successfully achieve unsupervised domain adaptation with adversarial network. Motivated by theory on domain adaptation Ben-David et al. (2010, 2007); Bousmalis et al. (2016) that a transferable feature is one for which an algorithm cannot learn to identify the domain of origin of the input observation.

2 Task Adversarial Loss for MTL

Inspired by adversarial networks Goodfellow et al. (2014), we proposed an adversarial shared-private model for multi-task learning, in which a shared recurrent neural layer is working adversarially towards a learnable multi-layer perceptron, preventing it from making an accurate prediction about the types of tasks. This adversarial training encourages shared space to be more pure and ensure the shared representation not be contaminated by task-specific features.

Discriminator is used to map the shared representation of sentences into a probability distribution, estimating what kinds of tasks the encoded sentence comes from.

Adversarial Loss

Different with most existing multi-task learning algorithm, we add an extra task adversarial loss LAdvL_{Adv} to prevent task-specific feature from creeping in to shared space. The task adversarial loss is used to train a model to produce shared features such that a classifier cannot reliably predict the task based on these features. The original loss of adversarial network is limited since it can only be used in binary situation. To overcome this, we extend it to multi-class form, which allow our model can be trained together with multiple tasks:

where dikd_{i}^{k} denotes the ground-truth label indicating the type of the current task. Here, there is a min-max optimization and the basic idea is that, given a sentence, the shared LSTM generates a representation to mislead the task discriminator. At the same time, the discriminator tries its best to make a correct classification on the type of task. After the training phase, the shared feature extractor and task discriminator reach a point at which both cannot improve and the discriminator is unable to differentiate among all the tasks.

Semi-supervised Learning Multi-task Learning

We notice that the LAdvL_{Adv} requires only the input sentence xx and does not require the corresponding label yy, which makes it possible to combine our model with semi-supervised learning. Finally, in this semi-supervised multi-task learning framework, our model can not only utilize the data from related tasks, but can employ abundant unlabeled corpora.

3 Orthogonality Constraints

We notice that there is a potential drawback of the above model. That is, the task-invariant features can appear both in shared space and private space.

Motivated by recently workJia et al. (2010); Salzmann et al. (2010); Bousmalis et al. (2016) on shared-private latent space analysis, we introduce orthogonality constraints, which penalize redundant latent representations and encourages the shared and private extractors to encode different aspects of the inputs.

After exploring many optional methods, we find below loss is optimal, which is used by Bousmalis et al. (2016) and achieve a better performance:

where F2\|\cdot\|_{F}^{2} is the squared Frobenius norm. Sk\bm{\mathbf{S}}^{k} and Hk\bm{\mathbf{H}}^{k} are two matrics, whose rows are the output of shared extractor Es(,;θs)E_{s}(,;\theta_{s}) and task-specific extrator Ek(,;θk)E_{k}(,;\theta_{k}) of a input sentence.

4 Put It All Together

The final loss function of our model can be written as:

where λ\lambda and γ\gamma are hyper-parameter.

The networks are trained with backpropagation and this minimax optimization becomes possible via the use of a gradient reversal layer Ganin and Lempitsky (2015).

Experiment

To make an extensive evaluation, we collect 16 different datasets from several popular review corpora.

The first 14 datasets are product reviews, which contain Amazon product reviews from different domains, such as Books, DVDs, Electronics, ect. The goal is to classify a product review as either positive or negative. These datasets are collected based on the raw data https://www.cs.jhu.edu/~mdredze/datasets/sentiment/ provided by Blitzer et al. (2007). Specifically, we extract the sentences and corresponding labels from the unprocessed original data Blitzer et al. (2007) also provides two extra processed datasets with the format of Bag-of-Words, which are not proper for neural-based models.. The only preprocessing operation of these sentences is tokenized using the Stanford tokenizer http://nlp.stanford.edu/software/tokenizer.shtml.

The remaining two datasets are about movie reviews. The IMDB datasethttps://www.cs.jhu.edu/~mdredze/datasets/sentiment/unprocessed.tar.gz consists of movie reviews with binary classes Maas et al. (2011). One key aspect of this dataset is that each movie review has several sentences. The MR dataset also consists of movie reviews from rotten tomato website with two classes https://www.cs.cornell.edu/people/pabo/movie-review-data/.Pang and Lee (2005).

All the datasets in each task are partitioned randomly into training set, development set and testing set with the proportion of 70%, 20% and 10% respectively. The detailed statistics about all the datasets are listed in Table 1.

2 Competitor Methods for Multi-task Learning

The multi-task frameworks proposed by previous works are various while not all can be applied to the tasks we focused. Nevertheless, we chose two most related neural models for multi-task learning and implement them as competitor methods.

MT-CNN: This model is proposed by Collobert and Weston (2008) with convolutional layer, in which lookup-tables are shared partially while other layers are task-specific.

MT-DNN: The model is proposed by Liu et al. (2015b) with bag-of-words input and multi-layer perceptrons, in which a hidden layer is shared.

3 Hyperparameters

The word embeddings for all of the models are initialized with the 200d GloVe vectors (Pennington et al. (2014)). The other parameters are initialized by randomly sampling from uniform distribution in [0.1,0.1][-0.1,0.1]. The mini-batch size is set to 16.

For each task, we take the hyperparameters which achieve the best performance on the development set via an small grid search over combinations of the initial learning rate [0.1,0.01][0.1,0.01], λ[0.01,0.1]\lambda\in[0.01,0.1], and γ[0.01,0.1]\gamma\in[0.01,0.1]. Finally, we chose the learning rate as 0.010.01, λ\lambda as 0.050.05 and γ\gamma as 0.010.01.

4 Performance Evaluation

Table 2 shows the error rates on 16 text classification tasks. The column of “Single Task” shows the results of vanilla LSTM, bidirectional LSTM (BiLSTM), stacked LSTM (sLSTM) and the average error rates of previous three models. The column of “Multiple Tasks” shows the results achieved by corresponding multi-task models. From this table, we can see that the performance of most tasks can be improved with a large margin with the help of multi-task learning, in which our model achieves the lowest error rates. More concretely, compared with SP-MTL, ASP-MTL achieves 4.1%4.1\% average improvement surpassing SP-MTL with 1.0%1.0\%, which indicates the importance of adversarial learning. It is noteworthy that for FS-MTL, the performances of some tasks are degraded, since this model puts all private and shared information into a unified space.

5 Shared Knowledge Transfer

With the help of adversarial learning, the shared feature extractor EsE_{s} can generate more pure task-invariant representations, which can be considered as off-the-shelf knowledge and then be used for unseen new tasks.

To test the transferability of our learned shared extractor, we also design an experiment, in which we take turns choosing 1515 tasks to train our model MSM_{S} with multi-task learning, then the learned shared layer are transferred to a second network MTM_{T} that is used for the remaining one task. The parameters of transferred layer are kept frozen, and the rest of parameters of the network MTM_{T} are randomly initialized.

More formally, we investigate two mechanisms towards the transferred shared extractor. As shown in Figure 4. The first one Single Channel (SC) model consists of one shared feature extractor EsE_{s} from MSM_{S}, then the extracted representation will be sent to an output layer. By contrast, the Bi-Channel (BC) model introduces an extra LSTM layer to encode more task-specific information. To evaluate the effectiveness of our introduced adversarial training framework, we also make a comparison with vanilla multi-task learning method.

As shown in Table 3, we can see the shared layer from ASP-MTL achieves a better performance compared with SP-MTL. Besides, for the two kinds of transfer strategies, the Bi-Channel model performs better. The reason is that the task-specific layer introduced in the Bi-Channel model can store some private features. Overall, the results indicate that we can save the existing knowledge into a shared recurrent layer using adversarial multi-task learning, which is quite useful for a new task.

6 Visualization

To get an intuitive understanding of how the introduced orthogonality constraints worked compared with vanilla shared-private model, we design an experiment to examine the behaviors of neurons from private layer and shared layer. More concretely, we refer to htjh_{tj} as the activation of the jj-neuron at time step tt, where t{1,,n}t\in\{1,\ldots,n\} and j{1,,d}j\in\{1,\ldots,d\}. By visualizing the hidden state hj\mathbf{h}_{j} and analyzing the maximum activation, we can find what kinds of patterns the current neuron focuses on.

Figure 5 illustrates this phenomenon. Here, we randomly sample a sentence from the validation set of Baby task and analyze the changes of the predicted sentiment score at different time steps, which are obtained by SP-MTL and our proposed model. Additionally, to get more insights into how neurons in shared layer behave diversely towards different input word, we visualize the activation of two typical neurons. For the positive sentence “Five stars, my baby can fall asleep soon in the stroller”, both models capture the informative pattern “Five stars” For this case, the vanilla LSTM also give a wrong answer due to ignoring the feature “Five stars”.. However, SP-MTL makes a wrong prediction due to misunderstanding of the word “asleep”.

By contrast, our model makes a correct prediction and the reason can be inferred from the activation of Figure 5-(b), where the shared layer of SP-MTL is so sensitive that many features related to other tasks are included, such as ”asleep”, which misleads the final prediction. This indicates the importance of introducing adversarial learning to prevent the shared layer from being contaminated by task-specific features.

We also list some typical patterns captured by neurons from shared layer and task-specific layer in Table 4, and we have observed that: 1) for SP-MTL, if some patterns are captured by task-specific layer, they are likely to be placed into shared space. Clearly, suppose we have many tasks to be trained jointly, the shared layer bear much pressure and must sacrifice substantial amount of capacity to capture the patterns they actually do not need. Furthermore, some typical task-invariant features also go into task-specific layer. 2) for ASP-MTL, we find the features captured by shared and task-specific layer have a small amount of intersection, which allows these two kinds of layers can work effectively.

Related Work

There are two threads of related work. One thread is multi-task learning with neural network. Neural networks based multi-task learning has been proven effective in many NLP problems Collobert and Weston (2008); Glorot et al. (2011).

Liu et al. (2016c) first utilizes different LSTM layers to construct multi-task learning framwork for text classification. Liu et al. (2016b) proposes a generic multi-task framework, in which different tasks can share information by an external memory and communicate by a reading/writing mechanism. These work has potential limitation of just learning a shared space solely on sharing parameters, while our model introduce two strategies to learn the clear and non-redundant shared-private space.

Another thread of work is adversarial network. Adversarial networks have recently surfaced as a general tool measure equivalence between distributions and it has proven to be effective in a variety of tasks. Ajakan et al. (2014); Bousmalis et al. (2016) applied adverarial training to domain adaptation, aiming at transferring the knowledge of one source domain to target domain. Park and Im (2016) proposed a novel approach for multi-modal representation learning which uses adversarial back-propagation concept.

Different from these models, our model aims to find task-invariant sharable information for multiple related tasks using adversarial training strategy. Moreover, we extend binary adversarial training to multi-class, which enable multiple tasks to be jointly trained.

Conclusion

In this paper, we have proposed an adversarial multi-task learning framework, in which the task-specific and task-invariant features are learned non-redundantly, therefore capturing the shared-private separation of different tasks. We have demonstrated the effectiveness of our approach by applying our model to 16 different text classification tasks. We also perform extensive qualitative analysis, deriving insights and indirectly explaining the quantitative improvements in the overall performance.

Acknowledgments

We would like to thank the anonymous reviewers for their valuable comments and thank Kaiyu Qian, Gang Niu for useful discussions. This work was partially funded by National Natural Science Foundation of China (No. 61532011 and 61672162), the National High Technology Research and Development Program of China (No. 2015AA015408), Shanghai Municipal Science and Technology Commission (No. 16JC1420401).

References