0%
Text Classification

Text Classification

Build a reliable text classifier: honest baselines, leak-free splits, metrics that don't lie, and systematic error analysis.

10-15 min

Text classification is the most profitable task in applied NLP. Sorting spam, routing support tickets to the right team, detecting an unhappy customer review, flagging a confidential document: in all of these cases, a text input must produce a label from a finite set.

It is also the task where it is easiest to be wrong about your own performance. A classifier that reports 97% accuracy on a problem where 97% of the examples belong to a single class has learned nothing: it always gives the same answer. A classifier trained on badly split data learns the identity of its examples rather than their content, and reports a score that production will brutally contradict.

That is why this lesson devotes as much space to evaluation as to training. Training a text model takes five lines of scikit-learn; knowing whether you can trust it takes a lot more. The order followed here is that of a real project: define the labels, assemble the data, set a dumb baseline, train, measure correctly, then look at the errors one by one.

The last step is the one everybody skips, and it is the one that drives progress. A model almost never improves by switching algorithms; it improves by understanding why it fails on fifty specific examples.

Link copied!