Text Classification

Assigning documents to predefined categories by learning from labeled examples. The classification problem, Naive Bayes and its two event models, feature selection, evaluation with micro- and macro-averaging, vector space classifiers, and experiments on Reuters-21578 and Goodreads reviews.

Retrieval answers a query that arrives once. Classification answers a question asked of every document as it arrives: whether a message is spam, whether a story is about corporate earnings, how many stars a review gives. This unit shows how a program learns to answer such a question from labeled examples, and how its answers are measured on documents it has not seen.

Text classification is the task of assigning documents to predefined classes. The rules could be written by hand, and in some settings still are. The approach that dominates is supervised learning. A person labels a set of example documents, and an algorithm learns from them a function that labels new documents automatically.

Classification belongs in a retrieval course for three reasons:

  • It is retrieval's twin. A standing query that filters a stream of news is a binary classifier, and a ranking function is a classifier that has not yet chosen a threshold.
  • It shares retrieval's representations. Documents are bags of terms built by the same text processing and weighted by the same statistics.
  • It shares retrieval's probability. Its first major method, Naive Bayes, rests on the same conditional independence assumption as the Binary Independence Model. The two are close relatives: one estimates the probability of relevance, the other the probability of a class.

Here is the route. First we set up the problem and watch a three-word rule hold its own against a learner. Then we build Naive Bayes in its two forms and show why a classifier built on a false assumption still chooses the right class. Next we choose which terms to use and measure how well a classifier does. Then we classify documents by their position in the vector space. Finally we apply classification to ranking itself, learning a ranking function from relevance judgments. One dataset runs through most of the unit: Reuters-21578, the news collection the textbook uses, and above all its category grain. The article on learning to rank returns to Cranfield, the collection of the retrieval units, because ranking needs queries with relevance judgments. A final article examines my course project, which used Naive Bayes to predict the star ratings of Goodreads reviews.

Articles

The problem

  • The text classification problem: a classifier is a function from documents to classes, learned from labeled examples, and learning pays when rules would be too many to write and maintain. Standing queries, hand-written rules versus learning (with a three-word rule that beats Naive Bayes on grain), binary, multiclass, and multilabel tasks, and training and test data.

Naive Bayes

  • Naive Bayes classification: Bayes' rule becomes a classifier for documents once a class is modeled as a distribution over terms. The multinomial model's generative story, its maximum likelihood estimates derived, add-one smoothing derived as a posterior mean under a uniform Dirichlet prior, how the smoothing constant changes decisions, computing in log space, Naive Bayes as a linear classifier, the training and classification procedure, and the textbook's worked example carried through every step.
  • The Bernoulli model and why Naive Bayes works: a model that records only which terms a document contains counts a repeated word once and counts absent words too, and it can reverse the multinomial model's decision. The second event model and its estimates derived, how its weights are the Binary Independence Model's, why a classifier needs only the right winner, and why its probabilities are badly calibrated.

Doing it well

  • Feature selection: a classifier can keep the terms that depart most from independence of the class and drop the rest. Mutual information and the χ² statistic derived from their definitions to formulas in four counts, and frequency, all worked by hand on Reuters counts, with experiments showing why mutual information suits the multinomial model poorly.
  • Evaluating classifiers: a classifier is measured by precision, recall and F1 on documents held out from training. Per-class measures, micro- and macro-averaging computed on Reuters, the decision threshold and the precision-recall trade-off, confusion matrices, baselines, cross-validation, and the size of the error made by testing on training documents.
  • Vector space classification: a document can be classified by the labeled documents it lies near. Rocchio and its hyperplane derived, k nearest neighbors, their decision regions in an interactive two-dimensional example, a comparison with Naive Bayes on Reuters, linear classifiers including the support vector machine and its margin, and the bias-variance trade-off.

Classification applied to ranking

  • Learning to rank: a ranking function can be learned from relevance judgments instead of designed. The textbook's two-feature classifier, pointwise, pairwise and listwise training (Ranking SVM, RankNet, LambdaRank, LambdaMART, ListNet), and an experiment on Cranfield in which four learned combinations of eight features barely improve on BM25.

A project

Course materials

The classifier I built with James R. Brown for our term project is in the Goodreads repository. The experiments on Reuters were written for this site.

References

  • Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, chapters 13–14. Cambridge University Press. record · 102 pages
  • Sebastiani, F. (2002). Machine learning in automated text categorization. ACM Computing Surveys, 34(1), 1–47. record · 3 pages

Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 16 Nov 2026 · 7 revisions