Working with Text: A Review Classifier
Computers can't read words directly, so we turn text into numbers. TF-IDF counts words, giving more weight to words that are rare across all texts.
Text is everywhere - reviews, emails, support tickets. To use it in ML, words are turned into numbers. TF-IDF is a classic, fast approach that still works well for many tasks, while modern language models understand meaning and context far better.
Example
What did it learn?
Example
With only 12 examples the model is unsure (scores near 0.5), and it even learned meaningless words like it and box. Real text models are trained on thousands of reviews.
Notice "not good" - the word good pushes positive, so simple word counts can miss meaning. Modern language models read whole sentences and understand this much better.
Key points
- TF-IDF turns text into weighted word counts.
- A pipeline joins the vectorizer and the model.
- Simple models miss word order and negation.
📝 Test yourself
1. Why convert text with TF-IDF?
2. What is a weakness of word-count models?
3. Fill in the class that turns text into TF-IDF numbers:
from sklearn.feature_extraction.text import
