Loading…
Glossary term
Assigning categories to pieces of text, such as spam or not spam.
Text classification assigns a category to a piece of text: spam or not, the topic of an article, the urgency of a ticket. Classic systems turn words into numbers and use a simple classifier, while modern ones fine-tune a language model. It is one of the most common practical NLP tasks.
A simple text classifier
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
clf = make_pipeline(TfidfVectorizer(), LogisticRegression())
clf.fit(["win a prize now", "lunch at noon"], ["spam", "ham"])
print(clf.predict(["claim your prize"]))It automates sorting and routing of large volumes of text.