Bayesian Optimization of Text Representations

When applying machine learning to problems in NLP, there are many choices to make about how to represent input texts. These choices can have a big effect on performance, but they are often uninteresting to researchers or practitioners who simply need a module that performs well. We propose an approach to optimizing over this space of choices, formulating the problem as global optimization. We apply a sequential model-based optimization technique and show that our method makes standard linear models competitive with more sophisticated, expensive state-of-the-art methods based on latent variable models or neural networks on various topic classification and sentiment analysis problems. Our approach is a first step towards black-box NLP systems that work with raw text and do not require manual tuning.


Introduction
NLP researchers and practitioners spend a considerable amount of time comparing machine-learned models of text that differ in relatively uninteresting ways.For example, in categorizing texts, should the "bag of words" include bigrams, and is tf-idf weighting a good idea?These choices matter experimentally, often leading to big differences in performance, with little consistency across tasks and datasets in which combination of choices works best.Unfortunately, these differences tell us little about language or the problems that machine learners are supposed to solve.
We propose that these decisions can be automated in a similar way to hyperparameter selection (e.g., choosing the strength of a ridge or lasso regularizer).Given a particular text dataset and classification task, we introduce a technique for optimizing over the space of representational choices, along with other "nuisances" that interact with these decisions, like hyperparameter selection. 1or example, using higher-order n-grams means more features and a need for stronger regularization and more training iterations.Generally, these decisions about instance representation are made by humans, heuristically; our work is the first to automate them.
We apply the technique to logistic regression on a range of topic and sentiment classification tasks.Consistently, our method finds representational choices that perform better than linear baselines previously reported in the literature, and that, in some cases, are competitive with more sophisticated non-linear models trained using neural networks.Classfication proceeds in three steps: first, x : I → R N maps each input to a vector representation.Second, a classifier is learned from the inputs (now transformed into vectors) and outputs:

Problem Formulation and Notation
, the composition of the representation function with the learned classifier).
Here we consider linear classifiers of the form where the coefficients w o ∈ R N , for each output o, are learned using logistic regression on the training data.We let w denote the concatenation of all w o .Hence the parameters can be understood as a function of the training data and the representation function x.The performance function f , in turn, is a function of the held-out data d dev and x-also w and d train , through x.For simplicity, we will write "f (x)" when the rest are clear from context.Typically, x is fixed by the model designer, perhaps after some experimentation, and learning focuses on selecting the parameters w.For logistic regression and many other linear models, this training step reduces to convex optimization in N |O| dimensions-a solvable problem that is still costly for large datasets and/or large output spaces.In seeking to maximize f with respect to x, we do not wish to carry out training any more times than necessary.
Choosing x can be understood as a problem of selecting hyperparameter values.We therefore turn to Bayesian optimization, a family of techniques recently introduced for selecting hyperparameter values intelligently when solving for parameters (w) is costly.

Bayesian Optimization
Our approach is based on sequential model-based optimization (SMBO; Hutter et al., 2011).It iteratively chooses representation functions x.
On each round, it makes this choice through a nonparametrically-estimated probabilistic model of f , then evaluates f -we call this a "trial."As in any iterative search algorithm, the goal is to balance exploration of options for x with exploitation of previously-explored options, so that a good choice is found in a small number of trials.See Algorithm 1.
More concretely, in the tth trial, x t is selected using an acquisition function A and a "surrogate" probabilistic model p t .Second, f is evaluated given x t -an expensive operation which involves training to select parameters w and assessing performance on the held-out data.Third, the probabilistic model is updated using a nonparametric estimator.
Algorithm We next describe the acquisition function A and the surrogate model p t used in our experiments.

Acquisition Function
A good acquisition function returns high values for x such that either the value f (x) is predicted to be high, or because uncertainty about f (x)'s value is high; balancing between these is the classic tradeoff between exploitation and exploration.We use a criterion called Expected Improvement (EI; Jones, 2001), which is the expectation (under the current surrogate model p t ) that the choice y will exceed y * : where y * is chosen depending on the surrogate model, discussed below.(For now, think of it as a strongly-performing "benchmark" value of f , discovered in earlier iterations.)Other options for the acquisition function include maximum probability of improvement (Jones, 2001), minimum conditional entropy (Villemonteix et al., 2006), Gaussian process upper confidence bound (Srinivas et al., 2010), or a combination of them (Hoffman et al., 2011).We selected EI because it is the most widely used acquisition function that has been shown to work well on a range of tasks.

Surrogate Model
As a surrogate model, we use a tree-structured Parzen estimator (TPE; Bergstra et al., 2011).This is a nonparametric approach to density estimation.We seek to estimate p t (y | x) where y = f (x), the performance function that is expensive to compute exactly.The TPE approach is as follows: where p < t and p ≥ t are densities estimated using observations from previous trials that are less than and greater than y * , respectively.In TPE, y * is defined as some quantile of the observed y; we use 15-quantiles.
As shown by Bergstra et al. (2011), the Expected Improvement in TPE can be written as: where γ = p t (y < y * ), fixed at 0.15 by definition of y * (above).Here, we prefer x with high probability under p ≥ t (x) and low probability under p < t (x).To maximize this quantity, we draw many candidates according to p ≥ t (x) and evaluate them according to p < t (x)/p ≥ t (x).Note that p(y) does not need to be given an explicit form.
In order to evaluate Eq. 2, we need to compute p < t (x) and p ≥ t (x).These joint distributions depend on the graphical model of the hyperparameter space-which is allowed to form a tree structure.
We discuss how to compute p < t (x) in the following.p ≥ t (x) is computed similarly, using trials where y ≥ y * .We associate each hyperparameter with a node in the graphical model; consider the kth dimension of x, denoted by random variable X k .
• If X k ranges over a discrete set X, TPE uses a reweighted categorical distribution, where the probability that X k = x is proportional to a smoothing parameter plus the counts of occurrences of a probability distribution by placing a truncated Gaussian distribution centered at each of x k k,1:t where y t < y * , with standard deviation set to the greater of the distances to the left and right neighbors.
In the simplest version, each node is independent, so we can compute p < t (x) by multiplying individual probabilities at every node.In the treestructured version, we only multiply probabilities along the relevant path, excluding some nodes.
Another common approach to the surrogate is the Gaussian Process (Rasmussen and Williams, 2006;Hoffman et al., 2011;Snoek et al., 2012).Like Bergstra et al. (2011), our preliminary experiments found the TPE to perform favorably.Further TPE's tree-structured configuration space is advantageous, because it allows nested definitions of hyperparameters, which we exploit in our experiments (e.g., only allows bigrams to be chosen if unigrams are also chosen).

Implementation Details
Because research on SMBO is active, many implementations are publicly available; we use the HPOlib library (Eggensperger et al., 2013). 2 The libray takes as input a function L, which is treated as a black box-in our case, a logistic regression trainer that wraps the LIBLINEAR library (Fan et al., 2008), based on the trust region Newton method (Lin et al., 2008)-and a specification of hyperparameters.

Experiments
Our experiments consider representational choices and hyperparameters for several text categorization problems.

Setup
We fix our learner L to logistic regression.We optimize text representation based on the types of n-grams used, the type of weighting scheme, and the removal of stopwords.For n-grams, we have two parameters, minimum and maximum lengths (n min and n max ).(All n-gram lengths between the minimum and maximum, inclusive, are used.)For weighting scheme, we consider term frequency, tf-idf, and binary schemes.Last, we also choose whether we should remove stopwords before constructing feature vectors for each document.
Furthermore, the choice of representation interacts with the regularizer and the training convergence criterion (e.g., more n-grams means slower training time).We consider two regularizers, 1 penalty (Tibshirani, 1996) or squared 2 penalty (Hoerl and Kennard, 1970).We also have hyperparameters for regularization strength and training convergence tolerance.See Table 1  huge (it is actually infinite since the regularization strength and convergence tolerance are continuous values, although we can also use sets of possible values), so exhaustive search is computationally expensive.In all our experiments for all datasets, we limit ourselves to 30 trials per dataset.The only preprocessing we applied was downcasing (see §5 for discussion about this).
We always use a development set to evaluate f (x) during learning and report the final result on an unseen test set.

Datasets
We evaluate our method on five text categorization tasks.
• Stanford sentiment treebank (Socher et al., 2013): a sentence-level sentiment analysis dataset for movie reviews from the rottentomatoes.comwebsite.We use the binary classification task where the goal is to predict whether a review is positive or negative (no neutral reviews).We obtained this dataset from http://nlp.stanford.edu/sentiment.• Electronics product reviews from Amazon (McAuley and Leskovec, 2013): this dataset consists of electronic product reviews, which is a subset of a large Amazon review dataset.Following the setup of Johnson and Zhang (2014), we only use the text section and ignore the summary section.We also only consider positive and negative reviews.We obtained this dataset from http://riejohnson.com/ cnn_data.html.• IMDB movie reviews (Maas et al., 2011) (Lang, 1995): the 20 Newsgroups dataset is a benchmark topic classification dataset, we use the publicly available copy at http://qwone.com/˜jason/20Newsgroups.There are 20 topics in this dataset.We derived four topic classification tasks from this dataset.The first task is to classify documents across all 20 topics.The second task is to classify related science documents into four science topics (sci.crypt,sci.electronics, sci.med, sci.med). 3The third and fourth tasks are talk.religion.miscvs. alt.atheismand comp.graphics vs. comp.windows.x.To consider a more realistic setting, we removed header information from each article since they often contain label information.
These are standard datasets for evaluating text categorization models, where benchmark results are available.In total, we have eight tasks, of which four are sentiment analysis tasks and four are topic classification tasks.See Table 2  statistics of our datasets.

Baselines
For each dataset, we select supervised, nonensemble classification methods from previous literature as baselines.In each case, we emphasize comparisons with the best-published linear method (often an SVM with a linear kernel with representation selected by experts) and the best-published method overall.In the followings, "SVM" always means "linear SVM".All methods were trained and evaluated on the same training/testing data splits; in cases where standard development sets were not available, we used a random 20% of the training data as a development set.

Results
We summarize the hyperparameters selected by our method, and the accuracies achieved (on test data) in Table 3.We discuss comparisons to baselines for each dataset in turn.
Stanford sentiment treebank (Table 4).Our logistic regression model outperforms the baseline SVM reported by Socher et al. (2013), who used only unigrams but did not specify the weighting scheme for their SVM baseline.While our result is still below the state-of-the-art based on the the recursive neural tensor networks (Socher et al., 2013) and the paragraph vector (Le and Mikolov, 2014), we show that logistic regression is comparable with recursive and matrix-vector neural networks (Socher et al., 2011;Socher et al., 2012).
Amazon electronics (Table 5).The bestperforming methods on this dataset are based on convolutional neural networks (Johnson and Zhang, 2014). 4Our method is on par with the  IMDB reviews (Table 6).The results parallel those for Amazon electronics; our method comes close to convolutional neural networks (Johnson and Zhang, 2014), which are state-of-the-art. 5It outperforms SVMs and feed-forward neural networks, the restricted Boltzmann machine approach presented by Dahl et al. (2012) Congressional vote (Table 7).Our method outperforms the best reported results of Yessenalina et al. (2010), which use a multi-level structured model based on a latent-variable SVM.We show comparisons to two well-known but weaker baselines, as well.
20 Newsgroups: all topics (Table 8).Our method outperforms state-of-the-art methods in-cluding the distributed structured output model (Srikumar and Manning, 2014). 7The strong logistic regression baseline from Paskov et al. ( 2013) uses all 5-grams, heuristic normalization, and elastic net regularization; our method found that unigrams and bigrams, with binary weighting and 2 penalty, achieved far better results.Our method achieves 86.3% and 92.1% using slightly different setups (see Table 3).

Discussion
Raw text as input and other hyperparameters.Our results suggest that seemingly mundane representation choices can raise the performance of simple linear models to be comparable with much more sophisticated models.Achieving these results is not a matter of deep expertise about the domain or engineering skill; the choices can be automated.Our experiments only considered logistic regression with downcased text; more choicesstemming, count thresholding, normalization of numbers, etc.-can be offered to the optimizer, as can additional feature options like gappy n-grams.
As NLP becomes more widely used in applications, we believe that automating these choices will be very attractive for those who need to train a high-performance model quickly.In each plot, the green solid line indicates the best accuracy found so far, while the dotted orange line shows accuracy at each trial.We can see that in general the model is able to obtain reasonably good representation in 30 trials.

Amazon
Optimized representations.For each task, the chosen representation is different.Out of all possible hyperparameter choices in our experiments (Table 1), each of them is used by at least one of the datsets (Table 3).For example, on the Congressional Vote dataset, we only need to use bigrams, whereas on the Amazon electronics dataset we need to use unigrams, bigrams, and trigrams.The binary weighting scheme works well for most of the datasets, except the sentence-level sentence analysis task, where the tf-idf weighting scheme was selected.2 regularization was best in all cases but one.
We do not believe that an NLP expert would be likely to make these particular choices, except through the same kind of trial-and-error process our method automates efficiently.Often, we believe, researchers in NLP make initial choices and stick with them through all experiments (as we have admittedly done with logistic regression).Optimizing over more of these choices will give stronger baselines.
Training time.We ran 30 trials for each dataset in our experiments.Figure 1 shows each trial accuracy and the best accuracy on development data as we increase the number of trials for three datasets.We can see that 30 trials are generally enough for the model to obtain good results, although the search space is large.
In the presence of unlimited computational resources, Bayesian optimization is slower than grid search on all hyperparameters, since the latter is easy to parallelize.This is not realistic in most research and development environments, and it is certainly impractical in increasingly widespread instances of personalized machine learning.The Bayesian optimization approach that we use in our experiments is performed sequentially.It attempts to predict what set of hyperparameters we should try next based on information from previous trials.There has been work to parallelize Bayesian optimization, making it possible to leverage the power of multicore architectures (Snoek et al., 2012;Desautels et al., 2012;Hutter et al., 2012).
Transfer learning and multitask setting.We treat each dataset independently and create a separate model for each of them.It is also possible to learn from previous datasets (i.e., transfer learning) or to learn from all datasets simultaneously (i.e., multitask learning) to improve performance.This has the potential to reduce the number of trials required even further.See Bardenet et al. (2013), Swersky et al. (2013), andYogatama andMann (2014) for how to perform Bayesian optimization in these settings.
Beyond linear models.We use logistic regression as our classification model, and our experiments show how simple linear models can be competitive with more sophisticated models given the right representation.Other models, can be considered, of course, as can ensembles (Yogatama and Mann, 2014).Increasing the number of options may lead to a need for more trials, and evaluating f (x) (e.g., training the neural network) will take longer for more sophisticated models.We have demonstrated, using one of the simplest classification models (logistic regression), that even simple choices about text representation can matter quite a lot.
Structured prediction problems Our framework could also be applied to structured prediction problems.For example, in part-of-speech tagging, the set of features can include character n-grams, word shape features, and word type features.The optimal choice for different languages is not always the same, our approach can automate this process.
Beyond supervised learning.Our framework could also be extended to unsupervised and semisupervised models.For example, in document clustering (e.g., k-means), we also need to construct representations for documents.Log-likelihood might serve as a performance function.A range of random initializations might be considered.Investigation of this approach for nonconvex problems like clustering is an exciting area for future work.

Conclusion
We used a Bayesian optimization approach to optimize choices about text representations for various categorization problems.Our sequential modelbased optimization technique identifies settings for a standard linear model (logistic regression) that are competitive with far more sophisticated stateof-the-art methods on topic classification and sentiment analysis.Every task and dataset has its own optimal choices; though relatively uninteresting to researchers and not directly linked to domain or linguistic expertise, these choices have a big effect on performance.We see our approach as a first step towards black-box NLP systems that work with raw text and do not require manual tuning.
Let the training data consist of a collection of pairs d train = d.i 1 , d.o 1 , . . ., d.i n , d.o n , where each input d.i ∈ I is a text document and each output d.o ∈ O, the output space.The overall training goal is to maximize a performance function f (e.g., classification accuracy, log-likelihood, F 1 score, etc.) of a machine-learned model, on a held-out dataset, d dev ∈ (I × O) n .

Figure 1 :
Figure1: Classification accuracies on development data for Amazon electronics (left), Stanford sentiment treebank (center), and congressional vote (right) datasets.In each plot, the green solid line indicates the best accuracy found so far, while the dotted orange line shows accuracy at each trial.We can see that in general the model is able to obtain reasonably good representation in 30 trials.

Table 1 :
for a complete list of hyperparameters in our experiments.Note that even with this limited number of options, the number of possible combinations is The set of hyperparameters considered in our experiments.The top half are hyperparameters related to text representation, while the bottom half are logistic regression hyperparameters, which also interact with the chosen representation.

Table 2 :
: a binary sentiment analysis dataset of highly Document counts.

Table 3 :
for descriptive Classification accuracies and the best hyperparameters for each of the dataset in our experiments."Acc" shows accuracies for our logistic regression model."Min" and "Max" correspond to the min n-grams and max n-grams respectively."Stop." is whether we perform stopwords removal or not."Reg." is the regularization type, "Strength" is the regularization strength, and "Conv." is the convergence tolerance.For regularization strength, we round it to the nearest integer for readability.