{'fraction_non_alphanumeric': 0.03391555027980329, 'fraction_numerical': 0.013362726810242496, 'mean_word_length': 4.7399260268639285, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learning How to Self-Learn: Enhancing Self-Training Using Neural Reinforcement Learning

Self-training is a useful strategy for semi-supervised learning, leveraging raw texts for enhancing model performances. Traditional self-training methods depend on heuristics such as model confidence for instance selection, the manual adjustment of which can be expensive. To address these challenges, we propose a deep reinforcement learning method to learn the self-training strategy automatically. Based on neural network representation of sentences, our model automatically learns an optimal policy for instance selection. Experimental results show that our approach outperforms the baseline solutions in terms of better tagging performances and stability.


Introduction
Scarcity of annotated data has motivated research into techniques capable of exploiting unlabeled data, e.g., domain adaptation, semi-supervised and unsupervised learning. Semi-supervised learning is useful for improving model performances when a target domain or language lacks of manual resources. Self-training is a commonly used strategy for various natural language processing (NLP) tasks, such as named entity recognition (NER) (Kozareva et al., 2005), part-of-speech (POS) tagging (Wang et al., 2007;Qi et al., 2009) and parsing (McClosky et al., 2006(McClosky et al., , 2008Sagae, 2010).
The basic idea of self-training is to augment the original training set with a set of automatic predictions. In particular, traditional self-training approaches train baseline models using a few instances with gold labels. Then the baseline models are used to predict a set of unlabeled data. The au-tomatically labeled instances are filtered based on certain strategies and then added to the training set for retraining new baseline models. This procedure continues until the number of automatically labeled instances reaches a budget or the model performance becomes stable. Theoretically, it resembles expectation-maximization (EM), giving local minimum to the training objective.
There have been different strategies for selecting automatically labeled data, the most typical one being the confidence values of the baseline models. How to define and measure the confidence of predictions is crucial for a successful self-training approach. Traditional self-training solutions are designed manually based on taskspecific heuristics (Rosenberg et al., 2005;Ardehaly and Culotta, 2016;Katz-Brown et al., 2011;Medlock and Briscoe, 2007;Daumé III, 2008). This can lead to two drawbacks: 1) manual adjustment of instance selection strategy is costly; 2) for the best effect on an unknown dataset, the source of information is limited to model confidence and a few other simple heuristics. As a result, linguistic characteristics of specific test sentences cannot be captured.
We aim to address this issue by leveraging neural models to represent test sentences, using reinforcement learning to automatically learn instance selection strategy. In particular, a self-training approach can be regarded as a decision process, where each step decides which automatically labeled instances can be selected. This decision process can be represented as a function that receives the automatically labeled instances as inputs and outputs a signal to indicate the acceptance or rejection of the prediction result. Since no gold labels exist for instance selection, we use deep Qnetwork (DQN) (Mnih et al., 2015;Guo, 2015;Fang et al., 2017) to learn selection strategy automatically, on the basis of the performance im-provements on a set of development data.A major advantage of our method as compared to traditional self-learning is that instance-level characteristics can be combined with model level confidence information using a neural model that is adaptively trained using reinforcement learning.
To evaluate the effectiveness of our proposal, we design and implement several self-training algorithms for the language-independent named entity recognition tasks and POS tasks. All the results show that our approach outperforms the baseline solutions in terms of performance and stability. Compared with manual heuristics, the deep Qnetwork model is capable of automatically learning the characteristics of training instances, and hence can potentially be more flexible in choosing the most useful data. Therefore, our approach is more general and can be applied to different NLP tasks. We release our code at http://anonymized. The remainder of this paper is organized as follow: Section 2 reviews the state-of-the-art literature on self-training and reinforcement learning for NLP tasks. Section 3 provides some background on the self-training process. Section 4 introduces our self-training methodology, elaborating in detail how the deep Q-network for selftraining is designed. Sections 5, 6 and 7 present our experimental setup for two typical NLP tasks, analyze the results, and explore the insights. Section 8 concludes the work and highlights some potential research issues.

Related Work
In this section, we briefly review previous work on reinforcement learning, self-training and domain adaptation in the NLP area. Self Training is a simple semi-supervised algorithm that has shown its effectiveness in parsing (McClosky et al., 2006(McClosky et al., , 2008Sagae, 2010), part of speech tagging (Wang et al., 2007;Qi et al., 2009), named entity recognition (Kozareva et al., 2005;Liu et al., 2013a), sentiment classification (Van Asch and Daelemans, 2016;Drury et al., 2011;Liu et al., 2013b), and other NLP tasks.
The performance of the self-training algorithms strongly depends on how automatically labeled data is selected at each iteration of the training procedure. Most of the current self-training approaches set up a threshold and treat a set of unlabeled examples as the high-confident prediction if its prediction is above the pre-defined threshold value. Such a selection metric may not provide a reliable selection (Chen et al., 2011).
Some researchers explore extra metrics as an auxiliary measurement to evaluate instances from unlabeled data. For example, Ardehaly and Culotta (2016) used coefficients learned from the model on the source domain as a selection metric and report a positive effect when applying self training in the target for hierarchical multi-label classification task. Katz-Brown et al. (2011) proposed to produce a ranked list of n-best predicted parses and selected the one yields the best external evaluation scored on the downstream external task (i.e., machine translation). Rosenberg et al. (2005) examined a few selection metrics for object detection task, and showed that detector-independent metric outperforms the more intuitive confidence metric. Various pseudo-labeled example selection strategies (Medlock and Briscoe, 2007;Daumé III, 2008) have been proposed. Zhou et al. (2012) explore a guided search algorithm to find informative unlabeled data subsets in the self-training process. The experimental results demonstrate that the proposed algorithm is in general more reliable and more effective than the standard self-training algorithm. These heuristic choices however require careful parameter tuning and domain specific information.
Most recently, Levati et al. (2017) proposed an algorithm to automatically identify an appropriate threshold from a candidate list for the reliability of predictions. The automatic selected threshold is used in the next iteration of self-training procedure. They scored each candidate threshold by evaluating whether the mean of the out of bag error between the examples with reliability score greater than the considered threshold is significantly different from the mean of the out of bag error of all the examples.
Self-training techniques have also been explored for domain adaptation by some researchers. Ardehaly and Culotta (2016) used self-training process to adapt the label proportion model from the source domain to the target domain. Chattopadhyay et al. (2012) generated pseudo-labels for the target data. Daumé III (2008) proposed a self training method in which several models are trained on the same dataset, and only unlabeled instances that satisfy the cross task knowledge constraints are used in the self training process. He and Zhou (2011) derived a set of self-learned and domain-specific features that were related to the distribution of the target classes for sentiment analysis task. Such self-learned features were then used to train another classifier by constraining the models predictions on unlabeled instances.
Note that although there have been many studies on how to apply self-training to NLP tasks, their self-training strategies are designed manually based on the heuristics of the NLP tasks. This makes it difficult to apply these approaches to a different NLP task or a different application scenario. Differently, we propose to design a general self-training approach by learning the self-training strategy automatically. In this way, our solution can be easily applied to different application domains.
There has also been recent studies on reinforcement learning for natural language processing, such as machine translation (Grissom II et al., 2014;Guo, 2015;Gu et al., 2016;Xia et al., 2016;Bahdanau et al., 2016), dialog systems Su et al., 2016), sentence simplification (Zhang and Lapata, 2017;Narayan et al., 2017), co-reference resolution (Clark and Manning, 2016) and latent structure induction (Yogatama et al., 2016;Lei et al., 2016). In particular, Guo (2015) proposed a deep Q-network model for text generation in sequence-to-sequence models. Fang et al. (2017) leveraged reinforcement learning for active learning, where a deep Q-network was used to learn the query policy for the active learners. However, to the best of our knowledge, there has been no previous attempt to embed self-training to deep reinforcement learning framework. The active learning work of Fang et al. (2017) is most similar to ours. However, different from active learning which needs to query human experts or oracle to provide gold labels, self-training associates instances with automatic prediction label. This makes our work substantially different from that of Fang et al. (2017).

Self-training
As explained in Section 1, we investigate how to learn a self-training approach that can be applied to multiple scenarios where the gold labels are not available (or partially available) and the efforts for human to annotate the labels are expensive. Our goal is to retrieve useful information from the massive unlabeled dataset to improve the training per- Algorithm 1: Self-training formance.
In traditional self-training framework (Algorithm 1), a tagger is first initialized using a set of instances with gold labels. Then, this tagger is used to tag a set of unlabeled data, and the tagging confidence for each unlabeled instance is evaluated. The automatically labeled instances with the highest confidence is added to the training set. The tagger is retrained using the updated training dataset and used to tag and select the unlabeled instances from the remaining dataset. This procedure is repeated until a given number of instances are selected and added to the training dataset.
How to measure the confidence of a tagging is crucial to a self-training approach. Traditional self-training approach usually requires human efforts to design specific confidence metrics based on the heuristics and application scenarios. This, however, is challenging and the effectiveness of the solution may depend on many factors, which however is not well investigated yet. We propose to learn a self-training strategy automatically.

Learning how to self-train
In order to learn a self-training function automatically, we design a deep reinforcement learning neural network to optimize the function parameters based on feedback from a set of development data. To formalize the self-training function easily, we adopt a stream-based strategy. That is, the unlabeled training dataset is regarded as a stream of instances. For every arriving unlabeled instance, the self-training function generates an output indicating whether this instance is selected or not. Given a stream of unlabeled dataset, our goal is to train the function that can make the decision automatically with a good performance via reinforce-Input: dataset train T, dev set D, unlabeled data U , budget; Algorithm 2: DQN-based self-training ment learning.

DQN-based self-training
Algorithm 2 shows the pseudocode for DQNbased self-training. Compared with Algorithm 1, Algorithm 2 is different in three aspects. First, when making a choice, Algorithm 2 randomly accesses an unlabeled instance, while Algorithm 1 needs to visit a batch of instances. Second, Algorithm 1 directly uses model confidence to choose instances, while Algorithm 2 train a DQN to learn a Q-function (qvalue), considering the confidence score and the test instance itself. Third, Algorithm 1 selects one instance for each iteration, while Algorithm 2 makes a choice only when the rejection score (qvalue[0]) is less than the acceptance score (qvalue[1]).

Model Structure
We implement the Q-function (qvalue in Algorithm 2) using a three-layered neural network, as shown in Fig. 1. The input layer represents the state of the learning framework. We adopt a similar approach proposed by Fang et al. (2017) to define the state of the framework, but we also integrate the hidden features from the tagger into the state. In particular, a state s consists of four elements (h s , h c , h p , h t ), where h s is the content representation of the arriving instance, h c is the confidence of tagging the instance using the tagger, h p is the marginals of the prediction for this instance, and h t is the hidden features from the tagger.
As shown in Fig. 1, to represent the content of an arriving instance, a convolution neural network (CNN) with 384 filters are designed, with the convolution size being (3, 4, 5), and 128 filters for each size, respectively. Each filter uses a linear transformation with a rectified linear unit activation function. The input to the CNN is the concatenated word embedding of the instance via looking up a pre-trained word embedding. These filters are used to extract the features of the instance contents. The filter outputs are then merged using a max-pooling operation to yield a hidden state h s , a vector of size 384 that represents the content of this instance.
The confidence of the tagger for an instance h c is defined based on the most probable label sequence for this instance. In this paper, we adopt in the experiment a Bi-LSTM-CRF tagger and its confidence value can be taken directly from the CRF tagger. This value can be also defined and measured for different taggers.
The marginals of the prediction for an instance is also calculated based on a CNN. The labels of the arriving instance are predicted using the tagger and 20 filters with a size of 3 are designed to extract the features in the prediction. These feature maps are then sub-sampled with mean pooling to capture the average uncertainty in each filter. The final hidden layer h p is used to represent the predictive marginals.
In order to extract the hidden features from the tagger, we explore the last hidden layers from the neural network of the tagger and output them to represent the hidden features of the tagger.
The four elements of the state s = (h s , h c , h p , h t ) are then used to calculate the second layer with a rectified linear unit activation function. This hidden layer is designed as a vector of size 256. Then it is used to calculate expected Q-value in the output layer, a vector of size 2, indicating whether the instance should be selected or not. If an instance is selected, the predicted labels of the sentences together with this sentence are added to the training set to retrain the tagger.

Training DQN
Training Goal. Reinforcement learning has been well adopted to learn a policy function in many applications scenarios. In this paper, similar to the setting in (Fang et al., 2017), we adopt the deep Q- Figure 1: The neural network for Q-function learning approach (Mnih et al., 2015) as our learning framework (denoted as DQN). In this learning framework, the policy function π is defined via a Q-function: Q π (s, a) → R, where s is the current state of learning framework, a is the action, and R is the reward of the framework when taking action a from the current state s. The training of the policy function π is to find the parameters that can maximize the reward of the each action in every state. This is done by iteratively updating Q π (s, a) using the rewards obtained from the sequence of actions during the training, based on the Bellman equation defined as follows: where R i = T t=i γ t−i r t is the discounted future rewards and γ ∈ [0, 1] is the discounting rate.
Reward. We define the reward for each action as follow. If an instance is not selected, then the reward is set to 0; otherwise, the reward of this action is defined as the performance difference of the tagger after the instance is added to the training set.
Following the approach of Mnih et al. (2015), we train the DQN using an experience replay mechanism. The current state, its actions and corresponding rewards are recorded in a memory. The parameters of DQN are learned using stochastic gradient descent to match the Q-values predicted by the DQN and the expected Q-values from the Bellman equation, r i + γmax a Q(s i+1 , a; θ). Samples are randomly selected from the experience memory to update the parameters of the DQN by minimizing the loss function: The training procedure is repeated with incoming instances. We conduct a significance test to decide whether a current training episode should be terminated. In the significance test, we calculate the performance difference between a series of consecutive actions. If the performance difference of the tagger is not significant, we terminate the training episode and restart the training with a new episode.
Algorithm. Algorithm 3 shows the pseudo code for DQN training. First, A initial set init is used to train the baseline tagger. Then, a random initialized DQN evaluate the Q-value of an instance sampled from the unlabeled set U . Then when the corresponding Q-value of acceptance is larger than that of rejection, the instance is selected. This raw instance together with its predicted labels is added to the training set. A new tagger is trained using the augmented training set. When a selection happens, the performance difference between the new tagger and the old tagger on the development data set is calculated as reward of the action. The reward is regarded as a feedback of the action and is used to update the parameters of the DQN neural network . The DQN neural network is self-trained for a given number of episodes. Once the performance on the development set is stable, the training of the DQN stops.

Tasks
The deep reinforcement learning neural network for self-learning can be used for various applica-Input: unlabeled data U , dev set D, initial set init; Output: DQN ; T ← init; while episode < 10000 do tagger ← train(T ); score ← test(tagger, D); while signif icant(score) do x ← a random instance from U ; U ← U \x; reward ← 0; qvalue ← DQN (x, tagger); if argmax(qvalue) == 1 then y ← tag(tagger, x); T ← T ∪ (x, y) ; tagger ← train(T ); newscore ← test(tagger, D); reward ← newscore − score; score ← newscore; end train DQN (x, tagger, reward); end episode ← episode + 1 ; end Algorithm 3: Self-train a DQN tion scenarios. In this section, we illustrate two typical application scenarios. Self Training for NER Tagging. In this scenario, we have a training set with gold labels, and a large number of unlabeled data. We need to apply a self-learning approach to improve the tagging performance using the unlabeled data.
We train the baseline NER tagger using the training dataset with gold labels. In Algorithm 2, the training set T means the labeled training set here.
Self Training for POS Tagging. In this scenario, we have a training set with gold labels from the source domain, and a large number of unlabeled data from different target domains. We need to apply a self-learning approach to improve the tagging performance using the unlabeled data for different target domains.
We train the baseline POS tagger using the source-domain dataset with gold labels. In Algorithm 2, the training set T means the sourcedomain training set here.
In the above two tasks, the DQN neural network is self-trained for a given number of episodes (c.f., Algorithm 3). Once the training of the DQN is finished, we use the DQN and the baseline model to select unlabeled instances. These selected instances are added together with the training dataset to train the tagger to verify the tagging performance.

Experiments
We conduct a series of experiments to evaluate our self-training based proposal for the aforementioned NER and POS tagging task.

Data
In the NER experiments, we use the training, development and evaluation data sets from the CoNLL 2002/2003 shared tasks (Sang;Tjong Kim Sang and De Meulder, 2003) for four different languages: English, German, Spanish and Dutch. The data set for each language consists of newswire text annotated with four entity categories: Location (LOC), Miscellaneous (MISC), Organization (ORG) and Person (PER). We use the existing corpus portions, with train used for policy training, testb used as development set for computing rewards, and final results are reported on testa.
The europarl-v7 raw dataset (Koehn, 2005) for machine translation is selected as the unlabeled data for the aforementioned four languages. A pretrained embedding for each language (Bojanowski et al., 2016) is used in the experiments.
In the cross-domain POS experiments, we use the SANCL2012 dataset. In this dataset, the ontonotes are used as the source domain, and the target domains include gweb-newsgroups, gwebreviews, gweb-emails, gweb-weblogs.

Baselines, Evaluation Metrics and Training Settings
To evaluate the effectiveness of the DQN-based solution, we also implement and test two baseline solutions, i.e., a random solution (denoted as RD) and a confidence-based self-training solution (denoted as T SL). In the T SL solution, the confidence is calculated based on the most probable label sequence under tagger (i.e., NER or POS), i.e. given a unlabeled sentence x i with n tokens, the confidence is defined as n max y p(y|x i ).
In both baseline approaches, the tagger (NER or POS) is initialed using the same instances as used in the DQN-based approach. For the random solution, a stream of input sentences are randomly selected and tagged by the tagger (NER or POS). In the NER experiments, we use a state-ofthe-art NER tagger, namely Sequence-Tagging NER tagger (Lample et al., 2016), as our baseline model. This NER tagger uses a Bi-LSTM on each sentence to generate contextual representation of each word, and then uses a CRF to decode the labels. We therefore consider extracting the contextual representation of words output by the Bi-LSTM as the hidden features of the NER tagger. That is, the DQN model uses the contextual representation of each word output by the Bi-LSTM in the NER tagger as h t . These contextual representation of words together with the confidence and marginal probability of the tagging are furthered manipulated by the DQN model to predict the action. In the POS experiments, a CRF model is used to implement the POS tagger.
In each training episode of DQN-based approach, if the latest 10 rewards in the episode is smaller than a given threshold (0.001), the performance change is regarded as not significant and this episode is terminated. To optimize the weights of the DQN, the DQN for each language is trained for 10000 episodes.  Table 1. We can observe that our DQN-based solution has a better performance than the two baseline solutions. In particular, Fig. 2(a) shows the English NER tagging scenario, where the F1-score of the our DQN-solution increases about 0.6% and then keeps stable at about 92.8%. The F1-score of T SL also increases, but the F1-score of the two baselines drop dramatically after adding more unla- beled sentences. Note that although the T SL approach has a sharp increase of performance at the moment of adding 50 unlabeled sentences, it is not stable compared to our DQN-based solution. We looked into the sentences selected by each solution, and found that T SL selects almost the sentences with no entities (around 95.6% of the selected sentences), because the sentences with no entities have a high confidence value. In contrast, DQN favors the sentences with more and diverse entities, occurring in around 54.1% of the selected sentences.

ID
In the Dutch NER tagging scenario, as shown in Fig. 2(b), we can observe that all the three approaches have an improvement of the performance when adding more and more unlabeled sentences. However, our DQN-based solution still outperforms the two baseline solutions because the performance of our solution increases more quickly and has a higher peak value than the two baseline solutions.
We can observe similar results for the Spanish and German NER tagging, as shown in Fig. 2(c) and Fig. 2(d), respectively. In general, our DQNbased approach has a better tagging performance (about 0.3% ∼ 1% improvement on average) and is more stable than the other two baseline solutions. A complete comparison of the performance can be found in Table. 1.

Self-learning for POS tagging
Settings. Similar to the setting in NER tagging, we also train and test the DQN combining the data for POS tagging. We initialize the POS tagger using the training set from the source domain (Ontonotes with gold labels). For each target domain (gweb-newsgroups, gweb-reviews, gwebemails, gweb-weblogs), we train a DQN using 10000 episodes, in each episode 4000 sentences  are selected. We compare the DQN-based selflearning solution with two baseline solutions (random and traditional self-learning) by adding the number of unlabeled sentences from 1 to 500.
Results. The testing results are shown in Table 3 and Fig. 3. We can observe that our DQN-based solution has a better performance than the two baseline solutions in each target domain. In particular, Fig. 3(a) shows that Ontonotes to Newgsgroup adaptation scenario, where the accuracy of the our DQN-solution increases about 0.03% compared to NO SL solution (can reach about 94.99% after adding 500 unlabeled instances). The accuracy of the two baselines also increase with the increasing number of unlabeled instance, but on average the accuracy of the DQNsolution is about 0.4% and 0.6% more than the T SL and RD solutions, respectively. Similar results can be observed for the Reviews and Emails scenarios, as shown in Fig. 3(b) and Fig. 3(b). In the Weblogs scenario, as shown in Fig. 3(c), the performance of RD solution increases slightly after adding a few unlabeled instances, and then drops dramatically. In contrast, the performance of the T SL and DQN solutions increases slowly. On average, the DQN solution has achieved an improvement of 0.04% than the T SL solution.
In the POS experiments, we also recorded the performance of the tagger during the training. of the DQN-solution increases slowly by adding the increasing number of unlabeled instances in all four scenarios (up to 0.3%). This shows that the DQN-based self-learning is effective in improving the training performance.
7 Case Study Table 2 shows some sample instances selected by T SL and DQN for NER tagging. Two PER and two LOC entities in Instance 1 are tagged accurately. Both T SL and DQN select this instance.
Community rules is wrongly tagged as ORG in Instance 2, leading to a low confidence score. However, DQN successfully learns to accept this prediction result. The LOC entity in this instance is correctly tagged. A similar phenomenon can be found in Instance 4, both the PER and LOC entities are tagged with a very low confidence score, whereas DQN learns to accept this prediction result. T SL assigns Instance 3 a very high confidence score because there are no named entities in this instance at all, whereas DQN learns to reject this instance. In addition, we find that the entity tag distribution on the dataset produced by DQN is much closer to the distribution on the original English training dataset than that generated by T SL. Figure 5 shows the overall distribution of the four entities on the three datasets. T SL produces surprisingly large number of PER entities and small number of MISC and ORG entities, while DQN generates less spiky distributions.

Conclusion
Learning a self-training strategy automatically can release the burden of human efforts in strategy design and is more flexible in choosing the most use-ful data. In this paper, we develop a deep reinforcement learning neural network to capture the characteristics of training instances automatically. Results show that our approach outperforms the baseline solutions in terms of a better tagging performance and stability. The current solution can be improved in several directions. For example, the input to the deep neural network does not include global tagging information of all the unlabeled instances. In addition, neural network structures other than CNN can be used to represent test sentences.