60-second card
Text classification
Text classification gives a whole text a label, like positive or negative, spam or not, or a topic.
- Start simple: TF-IDF features with logistic regression.
- Fine-tune a small transformer when you need more accuracy.
- Multi-label: a text can have several labels at once.
pos, neg = {"good", "love"}, {"bad", "awful"}
words = "i love this phone but the battery is bad".split()
score = sum(w in pos for w in words) - sum(w in neg for w in words)
print("positive" if score > 0 else "negative" if score < 0 else "neutral")Prints
neutralRemember: Always compare against a simple baseline.
Common mistake: Training on balanced data and deploying on data where 95% is one class.