Sub topic 13
Limitations and Where to Go Next
This chapter assumes that you understand supervised learning, TF-IDF features, logistic regression, train/test splits, and common classification metrics. The TF-IDF and logistic regression workflow is a strong baseline, but it does not understand language in the way a person does.
What the baseline can and cannot represent
A TF-IDF vector records which terms occur and how informative they are. It usually ignores the order in which terms appear. For example, these sentences contain nearly the same words:
- “The model rejected the input.”
- “The input rejected the model.”
Their meanings are different, but a unigram model may represent them similarly. Adding bigrams such as model rejected and rejected model captures some local order. It still does not represent the full structure of a sentence.
The model also treats each vocabulary item as a separate feature. It does not automatically know that automobile and car have related meanings. A document using unfamiliar words can therefore receive a poor prediction even when its meaning is clear to a person.
Words can also have several meanings. The word bank may refer to a financial institution or the side of a river. TF-IDF gives the word one feature. Its meaning depends on surrounding text, which this baseline does not model directly.
Common failure modes
Negation and long context
A bag-of-words model may learn that good suggests a positive label. It can struggle with sentences such as “not good” unless the training data contains enough useful phrases and the vectorizer includes suitable n-grams. Negation that spans many words is even harder.
Domain shift
Domain shift occurs when new documents differ from the training documents. A classifier trained on news articles may perform poorly on short customer messages. New vocabulary, different writing styles, and changed label meanings can all reduce performance.
Spurious clues and leakage
The classifier may rely on clues that correlate with a label in the training set but do not represent the real task. A user name, document template, or header can become a shortcut. Data leakage occurs when information from the test set or the future reaches training. Both problems can make evaluation look better than real-world performance.
Sparse and uneven data
Rare labels may have too few examples for the model to learn reliable weights. A high-dimensional vocabulary can also increase memory use and overfitting. Regularization helps, but it cannot create information that the training data does not contain.
Choosing the next step
Use error analysis before replacing the model. Group incorrect predictions by cause: missing vocabulary, confusing labels, negation, long documents, or a changed domain. Then choose the smallest change that addresses the observed problem.
| Observed problem | Practical next step | Trade-off |
|---|---|---|
| Word variations are missed | Add character n-grams or normalization | More features and computation |
| Local phrases matter | Add word bigrams or trigrams | Larger vocabulary and sparsity |
| Labels depend on meaning and context | Try embeddings or a transformer model | More compute and less transparency |
| Rare classes are ignored | Collect examples and use class weights | May reduce overall accuracy |
| Performance changes over time | Monitor drift and retrain | Requires operational work |
Character n-grams can help with spelling errors, prefixes, suffixes, and related word forms. A word-level model is often easier to explain, while a character-level model can be more tolerant of noisy text.
For tasks that depend heavily on word order, context, or subtle meaning, consider a pretrained language model. These models represent relationships between words and can be fine-tuned for classification. They usually require more memory, more careful deployment, and stronger controls for reproducibility and privacy.
A practical progression
The following progression keeps changes measurable:
Keep the original pipeline as a benchmark. Compare every new approach on the same held-out data, using metrics that match the cost of mistakes. A more complex model is worthwhile only when its improvement justifies its cost, maintenance, and reduced interpretability.
Exercise
A classifier has high accuracy but misses most documents from a small, important class. What should you investigate and change first?
Show answer
Inspect the confusion matrix and recall for that class, check the class distribution and label quality, and compare class-weighted training with macro-averaged metrics. Also inspect errors for leakage or a mismatch between the test set and production data.