Supervised Text Classification

Machine Learning
Introduced by
Machine-learning classification tradition (formalized for political text by Grimmer & Stewart; category-proportion variant by Hopkins & King)
Year
2013
Type
Supervised machine-learning classification of documents
Family
Text-as-data / content analysis

What does it do?

Supervised text classification trains a statistical model on documents that humans have hand-labeled, then uses it to assign categories (topic, tone, position, relevance) to a larger set of unlabeled documents.

Unlike dictionary methods, which apply a fixed word list, a classifier learns from examples which textual features predict each category, so it can pick up context-dependent cues. Grimmer and Stewart discuss these methods within the text-as-data literature and stress validation, while Hopkins and King argue that many social-science questions target accurate category proportions across a corpus rather than correct labels for every document.

The intuition behind the method

Think of it as training a research assistant. You give the model documents you have already coded, it learns which words and phrases tend to accompany each label, and it then codes new documents in the same way. The model does not read the text as a person does; it relies on statistical associations between features and labels. Its output is only as good as the training labels, and it is most reliable on text similar to what it was trained on, so its accuracy has to be checked on documents it did not see during training.

History

Supervised classification is a long-standing machine-learning task that political scientists adopted to scale up manual content analysis. Hopkins and King's article in the American Journal of Political Science (54(1), 2010; the online record is dated 2009) argued that the relevant target for social scientists is the proportion of documents in each category rather than per-document accuracy, and introduced a nonparametric estimator that gives approximately unbiased proportions even when the classifier performs poorly. Grimmer and Stewart's 2013 Political Analysis article surveys automated text methods, gives guidance on validating their output, and stresses that such methods are no substitute for careful thought and close reading.

When to use it

Use supervised classification when you have, or can afford to create, a reliable hand-labeled training set and your categories depend on context that a fixed word list cannot capture. It suits coding large corpora into a known scheme, such as topic, tone, stance, or relevance, and, through the Hopkins–King approach, estimating category proportions for descriptive or inferential work. It is less appropriate when labeled data cannot be produced, when the categories are not known in advance (unsupervised topic models are the alternative), or when the unlabeled corpus differs systematically from the training data, so the learned mapping may not hold; this applies to proportion estimation as well. In every case, validate out of sample.

Limitations and considerations

  • Requires a reliable hand-labeled training set, whose construction is costly and bounds the model's quality.
  • Generalizes poorly when the target corpus differs from the training data in topic, period, or style.
  • Standard bag-of-words classifiers ignore much syntax and discourse structure, limiting them on subtle or implicit categories.
  • Reported accuracy depends on the quality of labels and the representativeness of the test set; biased samples mislead.
  • Key assumptions: the labels validly capture the concept in the codebook, the training and target corpora are similar, the chosen classifier's own assumptions are reasonable (e.g., word independence given the category for naive Bayes), and the test set is representative.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Learns context-dependent and non-obvious cues from examples, which a fixed word list may miss.
  • Produces explicit out-of-sample performance estimates (precision, recall, F1), so reliability can be measured.
  • Lets human coding scale to large corpora once a training set exists.
  • Can target category proportions directly through the Hopkins–King approach, which is designed for aggregate rather than document-level inference.

Applications

  • Coding large corpora of speeches, bills, or articles into a predefined topic or policy scheme.
  • Classifying the tone or stance of statements toward parties, candidates, or policies.
  • Filtering relevant from irrelevant documents in a large collection before further analysis.
  • Estimating the proportion of social-media posts in each category for descriptive and over-time analysis.
  • Replicating and extending hand-coded content-analysis datasets at scale while reporting validated accuracy.

How it works

How it works

1

Human coders assign category labels to a sample of documents following an explicit codebook, with reliability checks across coders. This labeled set is the ground truth from which the model learns and against which it is judged, so the label scheme, coder training, and inter-coder agreement determine the ceiling on everything that follows.

2

Each document is turned into a numeric feature vector, typically a bag-of-words or n-gram representation after tokenizing, normalizing, removing stopwords and rare terms, and often weighting by term frequency–inverse document frequency. Richer features such as embeddings can replace counts. Feature choices trade off sparsity, interpretability, and the classifier's ability to generalize.

3

A classifier is fit on the labeled features to estimate how likely a document is to belong to each category. The formula shown is the naive Bayes case: each category is scored by its prior probability multiplied by the per-word likelihoods of the document's words, and the category with the highest posterior is predicted. Naive Bayes treats words as independent given the category, and it needs smoothing so that a word absent from a category in the training set does not force that category's probability to zero. Other classifiers, such as logistic regression, support vector machines, or neural models, learn a decision rule in feature space by different procedures, and the naive Bayes formula does not describe them.

Formula
P(c \mid d) \propto P(c)\prod_{w \in d} P(w \mid c)
4

Performance is estimated on held-out data the model never saw during training, using a train/test split or cross-validation, and reported with precision, recall, and their harmonic mean, the F1 score, alongside accuracy and a confusion matrix. Out-of-sample evaluation is non-negotiable: in-sample accuracy overstates performance because the model can memorize its training documents.

Formula
F_1 = \frac{2\,\text{precision}\cdot\text{recall}}{\text{precision} + \text{recall}}
5

Many social-science questions ask for the share of documents in each category rather than individual labels. Hopkins and King show that a classifier can have a high percentage of individual documents correctly classified and still produce a hugely biased estimate of category proportions when its predictions are simply counted. Their nonparametric method targets the proportions directly and, according to their abstract, gives approximately unbiased estimates even when the optimal classifier performs poorly. The displayed relation links the distribution of features in the target corpus to the distribution of features within each category, which is estimated from the labeled set, and the category proportions are solved for from it. Such an approach rests on the assumption that the relationship between features and categories in the labeled set carries over to the target corpus, so check that the training and target documents are comparable before relying on it.

Formula
P(D) = P(D \mid S)\,P(S), \quad P(D \mid S)\ \text{estimated from labeled data, solve for}\ P(S)

Common pitfalls

  • Reporting in-sample accuracy and skipping a held-out test or cross-validation, vastly overstating real performance.
  • Letting information leak from test to training (e.g., fitting preprocessing or feature selection on the full corpus) and inflating scores.
  • Averaging predicted labels to get category proportions, which is biased when the classifier errs — the problem Hopkins and King solve.
  • Trusting high overall accuracy on imbalanced classes, where a model can score well by ignoring the rare but substantively important category.

Frequently asked questions

How much hand-labeled training data do I need?

There is no fixed rule. The requirement depends on the number and balance of categories, how hard the distinctions are, and how rich the features are: clearly cued, binary distinctions need less data than fine-grained or rare categories. The practical test is a learning curve. Label in batches, evaluate out-of-sample performance as the training set grows, and stop when performance stops improving. Reliable labels matter more than volume, because the model cannot exceed the quality of its training codes.

Why estimate category proportions instead of just averaging predicted labels?

Because counting a classifier's predictions can give a biased share when the classifier errs, and a high percentage of correctly classified documents does not rule this out. Hopkins and King's method is designed for the proportion itself: according to their abstract, it gives approximately unbiased category proportions even when the optimal classifier performs poorly. Use it when your inference concerns aggregates rather than specific documents.

How does supervised classification differ from dictionary methods?

A dictionary method applies a fixed, analyst-specified word list and needs no training data, so it is transparent but can miss context. A supervised classifier learns the text-to-category mapping from hand-labeled examples, so it can capture context and non-obvious cues, but it requires labeled data and may generalize poorly to other corpora. Both can be validated, and many projects report a dictionary baseline alongside a supervised model. See dictionary-based-text-analysis.

Related methods

Sources

  1. Grimmer, J., & Stewart, B. M. (2013). Text as Data: The Promise and Pitfalls of Automatic Content Analysis Methods for Political Texts. Political Analysis, 21(3), 267–297.

    Open DOI reference
  2. Hopkins, D. J., & King, G. (2010). A Method of Automated Nonparametric Content Analysis for Social Science. American Journal of Political Science, 54(1), 229–247.

    Open DOI reference