A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Text Classification

Research Depth 95 in the knowledge graph ☐ I know this ☆ Set as goal
1topic build on this
642prerequisites beneath it
See this on the map →
Language Models and Neural Language ModelingSupervised Learning Fundamentals→→Sentiment Analysis in NLP
text-classification document-classification

Core Idea

Text classification assigns documents to predefined categories (spam, sentiment, topic, intent). Approaches range from TF-IDF with logistic regression to RNNs and Transformers. Class imbalance, large vocabularies, and variable document lengths are common challenges. Transfer learning from pretrained language models (BERT, GPT) dramatically improves performance.

Explainer

Text classification is the task of assigning a document — an email, a tweet, a product review, a support ticket — to one or more predefined categories. You have already encountered supervised learning and language models as prerequisites, and text classification sits at their intersection: it applies supervised learning to text data, using the representations that language modeling provides. The fundamental challenge is that text is variable-length, unstructured, and high-dimensional. A vocabulary of 50,000 words means each document lives in a 50,000-dimensional space, most of which is zeros. The history of text classification is largely a story of finding better ways to represent documents as fixed-length numerical vectors that classifiers can consume.

The classical approach is bag-of-words with TF-IDF weighting. Each document becomes a vector of word frequencies, weighted so that common words like "the" count less and distinctive words like "mortgage" count more. A logistic regression or support vector machine trained on these vectors works surprisingly well for many tasks — spam detection, topic classification, language identification. The bag-of-words representation discards word order entirely ("dog bites man" and "man bites dog" are identical), yet for many classification tasks, the presence or absence of key words carries most of the signal. This is the same insight that makes naive Bayes effective: which words appear matters more than how they are arranged, at least for coarse categorization.

When word order and context matter — as in sentiment analysis, where "not good" means the opposite of "good" — sequential and contextual models take over. Recurrent neural networks process text word by word, maintaining a hidden state that accumulates context, and the final hidden state serves as a document representation for classification. Convolutional models slide filters over word sequences to capture local n-gram patterns. But the dominant modern approach is transfer learning from pretrained Transformer-based language models like BERT. These models are trained on massive text corpora to develop rich, contextual word representations, and they can be fine-tuned for classification by adding a simple classification layer on top. Fine-tuning adapts the general language understanding to your specific task with relatively little labeled data — a few thousand examples often suffice where bag-of-words methods might need tens of thousands.

Practical text classification involves several recurring challenges. Class imbalance is common: in fraud detection, 99.9% of transactions are legitimate, so a classifier that always predicts "not fraud" achieves 99.9% accuracy while being useless. Strategies include oversampling the minority class, undersampling the majority, or adjusting the loss function to penalize minority-class errors more heavily. Preprocessing decisions — lowercasing, stemming, removing stop words, handling out-of-vocabulary tokens — can significantly affect performance, especially for classical methods. And evaluation must go beyond accuracy: precision, recall, and F1-score per class reveal whether the model is actually learning the categories you care about, particularly the rare ones.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Dividing Integers → Unit Rates → Proportions → Percent Concept → Converting Between Fractions, Decimals, and Percents → Operations with Rational Numbers → Two-Step Equations → Solving Multi-Step Equations → Equations with Variables on Both Sides → Angle Pairs: Complementary, Supplementary, and Vertical → Parallel Lines and Transversals → Corresponding Angles → Alternate Interior Angles → Triangle Angle Sum Theorem → Exterior Angle Theorem → Triangle Inequality Theorem → Similar Triangles: AA Similarity → Similar Triangles: SSS and SAS Similarity → Proportions in Similar Triangles → Right Triangle Trigonometry Introduction → Sine, Cosine, and Tangent Ratios → Trigonometric Ratios Review → Radian Measure → Converting Between Degrees and Radians → The Unit Circle → Graphing Sine and Cosine → Graphing Tangent and Reciprocal Trigonometric Functions → Derivatives of Trigonometric Functions → Antiderivatives → Indefinite Integrals → Basic Integration Rules → Riemann Sums → Definite Integral Definition → Probability Density Functions and Continuous Distributions → Cumulative Distribution Functions → Continuous Random Variables → Probability Density Functions → Expected Value → Linear Regression in Machine Learning → Neural Network Fundamentals → Attention Mechanisms → Transformer Architecture → Language Models and Neural Language Modeling → Text Classification

Longest path: 96 steps · 642 total prerequisite topics

Prerequisites (2)

Leads To (1)