A RL package for Torch that can also be used with openai gym
We propose to model the text classification process as a sequential decision process. In this process, an agent learns to classify documents into topics while reading the document sentences sequentially and learns to stop as soon as enough information was read for deciding. The proposed algorithm is based on a modelisation of Text Classification as a Markov Decision Process and learns by using Reinforcement Learning. Experiments on four different classical mono-label corpora show that the proposed approach performs comparably to classical SVM approaches for large training sets, and better for small training sets. In addition, the model automatically adapts its reading process to the quantity of training information provided.READ FULL TEXT VIEW PDF
In early years, text classification is typically accomplished by
While existing hierarchical text classification (HTC) methods attempt to...
Reading comprehension models are based on recurrent neural networks that...
This paper explores a simple and efficient baseline for text classificat...
The task of text classification is usually divided into two stages: tex...
We propose a Label Propagation based algorithm for weakly supervised tex...
Recent efforts in bioinformatics have achieved tremendous progress in th...
A RL package for Torch that can also be used with openai gym
Text Classification (TC) is the act of taking a set of labeled text documents, learning a correlation between a document’s contents and its corresponding labels, and then predicting the labels of a set of unlabeled test documents as best as possible. TC has been studied extensively, and is one of the older specialties of Information Retrieval. Classical statistical TC approaches are based on well-known machine learning models such as generative models — Naive Bayes for example
— or discriminant models such as Support Vector Machines. They mainly consider the bag of words representation of a document (where the order of the words or sentences is lost) and try to compute a category score by looking at the entire document content. Linear SVMs in particular — especially for multi-label classification with many binary SVMs — have been shown to work particularly well . Some major drawbacks to these global methods have been identified in the literature:
These methods take into consideration a document’s entire word set in order to decide to which categories it belongs. The underlying assumption is that the category information is homogeneously dispatched inside the document. This is well suited for corpora where documents are short, with little noise, so that global word frequencies can easily be correlated to topics. However, these methods will not be well suited in predicting the categories of large documents where the topic information is concentrated in only a few sentences.
Additionally, for these methods to be applicable, the entire document must be known at the time of classification. In cases where there is a cost associated with acquiring the textual information, methods that consider the entire document cannot be efficiently or reliably applied as we do not know at what point their classification decision is well-informed while considering only a subset of the document.
Considering these drawbacks, some attempts have been made to use the sequential nature of these documents for TC and similar problems such as passage classification. The earliest models developed especially for sequence processing extend Naive Bayes with Hidden Markov Models. Denoyer et al. propose an original model which aims at modeling a document as a sequence of irrelevant and relevant sections relative to a particular topic. In 
, the authors propose a model based on recurrent Neural Networks for document routing. Other approaches have proposed to extend the use of linear SVMs to sequential data, mainly through the use of string kernels. Finally, sequential models have been used for Information Extraction [8, 9], passage classification [10, 11], or the development of search engines [12, 13].
We propose a new model for Text Classification that is less affected by the aforementioned issues. Our approach models an agent that sequentially reads a text document while concurrently deciding to assign topic labels. This is modeled as a sequential process whose goal is to classify a document by focusing on its relevant sentences. The proposed model learns not only to classify a document into one or many classes, but also when to label, and when to stop reading the document. This last point is very important because it means that the systems is able to learn to label a document with the correct categories as soon as possible, without reading the entire text.
The contributions of this paper are three-fold:
We propose a new type of sequential model for text classification based on the idea of sequentially reading sentences and assigning topics to a document.
Additionally, we propose an algorithm using Reinforcement Learning that learns to focus on relevant sentences in the document. This algorithm also learns when to stop reading a document so that the document is classified as soon as possible. This characteristic can be useful for documents where sentence acquisition is expensive, such as large Web documents or conversational documents.
We show that on popular text classification corpora our model outperforms classical TC methods for small training sets and is equivalent to a baseline SVM for larger training sets while only reading a small portion of the documents. The model also shows its ability to classify by reading only a few sentences when the classification problem is easy (large training sets) and to learn to read more sentences when the task is harder (small training sets).
This document is organized as follows: In Section 2, we present an overview of our method. We formalize the algorithm as a Markov Decision Process in Section 3 and detail the approach for both multi-label and mono-label TC. We then present the set of experiments made on four different text corpora in Section 4.
Let denote the set of all possible textual documents, and the set of categories numbered from to . Each document in is associated with one or many111In this article, we consider both the mono-label classification task, where each document is associated with exactly one category, and the multi-label task where a document can be associated with several categories. categories of . This label information is only known for a subset of documents called training documents, composed of documents denoted . The labels of document are given by a vector of scores . We assume that:
The goal of TC is to compute, for each document in , the corresponding score for each category. The classification function with parameters is thus defined as :
Learning the classifier consists in finding an optimal parameterization that reduces the mean loss such that:
is a loss function proportional to the classification error of.
This section aims to provide an intuitive overview of our approach. The ideas presented here are formally presented in Section 3, and will only be described in a cursory manner below.
We propose to model the process of text classification as a sequential decision process. In this process, our classifier reads a document sentence-by-sentence and can decide — at each step of the reading process — if the document belongs to one of the possible categories. This classifier can also chose to stop reading the document once it considers that the document has been correctly categorized.
In the example described in Fig. 1, the task is to classify a document composed of 4 sentences. The documents starts off unclassified, and the classifier begins by reading the first sentence of the document. Because it considers that the first sentence does not contain enough information to reliably classify the document, the classifier decides to read the following sentence. Having now read the first two sentences, the classifier decides that it has enough information at hand to classify the document as cocoa.
The classifier now reads the third sentence and — considering the information present in this sentence — decides that the reading process is finished; the document is therefore classified in the cocoa category.
Had the document belonged to multiple classes, the classifier could have continued to assign other categories to the document as additional information was discovered.
In this example, the model took four actions: next, classify as cocoa, next and then stop. The choice of each action was entirely dependent on the corresponding state of the reading process. The choice of actions given the state, such as those picked while classifying the example document above, is called the policy of the classifier. This policy — denoted — consists of a mapping of states to actions relative to a score. This score is called a Q-value — denoted — and reflects the worth of choosing action during state of the process. Using the Q-value, the inference process can be seen as a greedy process which, for each timestep, chooses the best action defined as the action with the highest score w.r.t. :
The learning process consists in computing a -222The Q-function is an approximation of . which minimizes the classification loss (as in equation (3)) of the documents in the training set. The learning procedure uses a monte-carlo approach to find a set of good and bad actions relative to each state. Good actions are actions that result in a small classification loss for a document. The good and bad actions are then learned by a statistical classifier, such as an SVM.
An example of the training procedure on the same example document as above is illustrated in Fig 2. To begin with, a random state of the classification process is picked. Then, for each action possible in that state, the current policy is run until it stops and the final classification loss is computed. The training algorithm then builds a set of good actions — the actions for which the simulation obtains the minimum loss value — and a set of remaining bad actions. This is repeated on many different states and training documents until, at last, the model learns a classifier able to discriminate between good and bad actions relative to the current state.
We have presented the principles of our approach and given an intuitive description of the inference and learning procedures. We will now formalize this algorithm as a Markov Decision Process (MDP) for which an optimal policy is found via Reinforcement Learning. Note that we will only go over notations pertinent to our approach, and that this section lacks many MDP or Reinforcement Learning definitions that are not necessary for our explanation.
A Markov Decision Process (MDP) is a mathematical formalism to model sequential decision processes. We only consider deterministic MDPs, defined by a 4-tuple: . Here, is the set of possible states, is the is the set of possible actions, and is the state transition function such that (this symbolizes the system moving from state to state by applying action ). The reward, , is a value that reflects the quality of taking action in state relative to the agent’s ultimate goal. We will use to refer to the set of possible actions available to an agent in a particular state .
An agent interacts with the MDP by starting off in a state . The agent then chooses an action which moves it to a new state by applying the transition . The agent obtains a reward and then continues the process until it reaches a terminal state where the set of possible actions is empty i.e .
Let us define , a stochastic policy such that ,
with probability. The goal of RL is to find an optimal policy that maximizes the cumulative reward obtain by an agent. We consider here the finite-horizon context for which the cumulative reward corresponds to the sum of the reward obtained at each step by the system, following the policy . The goal of Reinforcement Learning is to find an optimal policy denoted which maximizes the cumulative reward obtained for all the states of the process i.e.:
Many algorithms have been developed for finding such a policy, depending on the assumptions made on the structure of the MDP, the nature of the states (discrete or continuous), etc. In many approaches, a policy is defined through the use of a - which reflects how much reward one can expect by taking action on state . With such a function, the policy is defined as:
In such a case, the learning problem consists in finding the optimal value which results in the optimal policy .
Due to the very large number of states we are facing in our approach, we consider the Approximated Reinforcement Learning context where the function is approximated by a parameterized function , where is a set of parameters such that:
where denotes the dot product and is a feature vector representing the state-action pair . The learning problem consists in finding the optimal parameters that results in an optimal policy:
Formally, we consider that a document is composed of a sequence of sentences such that , where is the i-th sentence of the document and is the total number of sentences making up the document. Each sentence has a corresponding feature vector — a normalized tf-idf vector in our case — that describes its content.
We can describe our sequential decision problem using an MDP. Below, we describe the MDP for the multilabel classification problem, of which monolabel classification is just a specific instance:
Each state is a triplet such that:
is the document the agent is currently reading.
corresponds to the current sentence being read; this implies that to have already been read.
is the set of currently assigned categories — categories previously assigned by the agent during the current reading process — where iff the document has been assigned to category during the reading process, otherwise.
The set of actions is composed of:
One or many classification actions denoted classify as for each category where . These actions correspond to assigning document to category .
A next sentence action denoted next which corresponds to reading the next sentence of the document.
A stop action denoted stop which corresponds to finishing the reading process.
The set of transitions act such that:
halts the decision process.
The reward is defined as:
where is the real vector of categories for and is the predicted vector of categories at the end of the classification process. The score of a single document is defined as:
In mono-label classification, we restrict the set of possible actions. The classify as k action leads to a stopping state such that . This brings the episode to an end after the attribution of a single label. Note that in the case of a mono-label system — where only one category can be assigned to a document — the reward corresponds to a classical accuracy measure: if the chosen category is correct, and otherwise.
We must now define a feature function which provides a vector representation of a state-action pair . The purpose of this vector is to be able to present to a statistical classifier to know whether it is good or bad. Comparing the scores of various pairs for a given state allows us to choose the best action for that state.
Classical text classification methods only represent documents by a global — and usually tf-idf weighted — vector. We choose, however, to include not only a global representation of the sentences read so far, but also a local component corresponding to the most recently read sentence. Moreover, while in state , a document may have been already assigned to a set of categories; the global feature vector must describe all this information. The vector representation of a state is thus defined as :
is the concatenation of a set of sub-vectors describing: the mean of the feature vectors of the read sentences, the feature vector of the last sentence, and the set of already assigned categories.
In order to include the action information, we use the block-vector trick introduced by  which consists in projecting into a higher dimensional space such that:
The position of inside the global vector is dependent on action . This results in a very high dimensional space which is easier to classify in with a linear model.
In order to find the best classification policy, we used a recent Reinforcement Learning algorithm called Approximate Policy Iteration with Rollouts. In brief, this method uses a monte-carlo approach to evaluate the quality of all the possible actions amongst some random sampled states, and then learns a classifier whose goal is to discriminate between the good and bad actions relative to each state. Due to a lack of space, we do not detail the learning procedure here and refer to the paper by Lagoudakis et al . An intuitive description of the procedure is given in Section 2.1.
We have applied our model on four different popular datasets: three mono-label and one multi-label. All datasets were pre-processed in the same manner: all punctuation except for periods were removed, SMART stop-words and words less than three characters long were removed, and all words were stemmed with Porter stemming. Baseline evaluations were performed with libSVM on normalized tf-idf weighted vectorial representations of each document as has been done in . Published performance benchmarks can be found in  and . The datasets are:
The Reuters-21578333http://web.ist.utl.pt/%7Eacardoso/datasets/ dataset which provides two corpora:
The Reuters8 corpus, a mono-label corpus composed of the 8 largest categories.
The Reuters10 corpus, a multi-label corpus composed of the 10 largest categories.
The WebKB444http://www.cs.cmu.edu/afs/cs.cmu.edu/project/theo-20/www/data/ dataset is a mono-label corpus composed of Web pages dispatched into 4 different categories.
The 20 Newsgroups555http://people.csail.mit.edu/jrennie/20Newsgroups/ (20NG) dataset is a mono-label corpus of news composed of 20 classes.
|Corpus||Nb of documents||Nb of categories||Nb of sentences by doc.||Task|
Many classification systems are soft classification systems that compute a score for each possible category-document pair. Our system is a hard classification system that assigns a document to one or many categories, with a score of either 1 or 0. The evaluation measures used in the litterature, such as the breakeven point, are not suitable for hard classification models and cannot be used to evaluate and compare our approach with other methods. We have therefore chosen to use the micro-F1 and macro-F1 measures. These measures correspond to a classical score computed for each category and averaged over the categories. The macro-F1 measure does not take into account the size of the categories, whereas the micro-F1 average is weighted by the size of each category. We averaged the different models’ performances on various train/test splits that were randomly generated from the original dataset. We used the same approach both for evaluating our approach and the baseline approaches to be able to compare our results properly. For each training size, the performance of the models were averaged over 5 runs. The hyper-parameters of the SVM and the hyper-parameters of the RL-based approach were manually tuned. What we present here are the best results obtained over the various parameter choices we tested. For the RL approach, each policy was learned on 10,000 randomly generated states, with 1 rollout per state, using a random initial policy. It is important to note that, in a practical sense, the RL method is not much more complicated to tune than a classical SVM since it is rather robust regarding the values of the hyper-parameters.
Our performance figures use SVM to denote baseline Support Vector Machine performance, and STC (Sequential Text Classification) to denote our approach. In the case of the mono-label experiments (Figure 3 and 4-left), performance of both the SVM method and our method are comparable. It is important to note, however, that in the case of small training sizes (1%, 5%), the STC approach outperforms SVM by 1-10% depending on the corpus. For example, on the R8 dataset we can see that for both F1 scores, STC is better by with a training size of 1%. This is also visible with the NewsGroup dataset, where STC is better by 10% for both metrics using a 1% training set. This shows that STC is particularly advantageous with small training sets.
The reading process’ behaviour is explored in Figure 5. Here, Reading Size corresponds to the mean percentage of sentences read for each document666If is the number of sentences in document read during the classification process, and is the total number of sentences in this document. Let be the number of test documents, then the reading size value is .. We can see that Reading Size decreases as the training size gets bigger for mono-label corpora. This is due to the fact that the smaller training sizes are harder to learn, and therefore the agent needs more information to properly label documents. In the right-hand side of Figure 5, we can see a histogram of number of documents grouped by Reading Size. We notice that although there is a mean Reading Size
of 41%, most of the documents are barely read, with a few outliers that are read until the end. The agent is clearly capable of choosing to read more or less of the document depending on its content.
In the case of multi-label classification, results are quite different. First, we see that for the R10 corpus, our model’s performance is lower than the baseline on large training sets. Moreover, the multi-label model reads all the sentences of the document during the classification process. This behaviour seems normal because when dealing with multi-label documents, one cannot be sure that the remaining sentences will not contain relevant information pertaining to a particular topic. We hypothesize that the lower performances are due to the much larger action space in the multi-label problem, and the fact that we are learning a single model for all classes instead of one independent models per class.
We have presented a new model that learns to classify by sequentially reading the sentences of a document, and which labels this document as soon as it has collected enough information. This method shows some interesting properties on different datasets. Particularly in mono-label TC, the model automatically learns to read only a small part of the documents when the training set is large, and the whole documents when the training set is small. It is thus able to adapt its behaviour to the difficulty of the classification task, which results in obtaining faster systems for easier problems. The performances obtained are close to the performance of a baseline SVM model for large training sets, and better for small training sets.
This work opens many new perspectives in the Text Classification domain. Particularly, it is possible to imagine some additional MDP actions for the classification agent allowing the agent to parse the document in a more complex manner. For example, this idea can be extended to learn to classify XML documents reading only the relevant parts.
This work was partially supported by the French National Agency of Research (Lampada ANR-09-EMER-007).