Python text classification libraries

Updated Nov 2026

Python text classification libraries assign one or more labels to a piece of text, such as a topic, an intent, or a sentiment. A zero-shot model scores labels chosen at runtime rather than labels fixed during training. These libraries let support tools, content filters, and AI agents route text by what it says.

Popularity

scikit-learn has the most monthly downloads in this comparison, at 214.9M, a count that covers all its machine learning work.

LibraryMonthly downloadsStarsLast releaseLicense
scikit-learn
214.9M
68.2KSep 2026BSD-3-Clause
Transformers
120.5M
169.1KNov 2026Apache-2.0
nltk
48.7M
14.8KOct 2026Apache-2.0
spacy
25.2M
34.0KOct 2026MIT
catboost
6.9M
9.2KFeb 2026Apache-2.0
textblob
3.2M
9.6KJul 2026MIT
fastText
2.2M
26.5KJun 2024MIT
keras-hub
471.7K
999Nov 2026Apache-2.0
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Combines a text feature vectorizer with a classifier in a pipeline.

Downloads / mo
214.9M
Stars
68.2K
Last release
1.9.1
License
BSD-3-Clause

Strengths

  • Combines text with structured features. Transform separate input columns and concatenate their features before classification.
  • Tunes complete text pipelines. Search vectorizer and classifier settings together.

Limitations

  • Unigrams lose word order. Use word n-grams when short phrases carry the label.
$ python -m pip install scikit-learn==1.9.1
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression

model = Pipeline([("text", TfidfVectorizer()), ("classifier", LogisticRegression())])
model.fit(["invoice due", "pay invoice", "reset password", "forgot password"],
          ["billing", "billing", "account", "account"])
print(model.predict(["invoice"]))

scikit-learn examples

From open-source projects on GitHub

Scores runtime candidate labels through sequence models trained for natural language inference.

Downloads / mo
120.5M
Stars
169.1K
Last release
5.23.0
License
Apache-2.0

Strengths

  • Accepts labels at prediction time. Choose candidate classes without fixing the output labels during model training.
  • Fine-tunes sequence classifiers. Train a classification model with the task’s label mappings.

Limitations

  • Zero-shot needs entailment models. Use models trained to judge whether text supports a candidate label.
  • Long zero-shot inputs are truncated. Split long documents before candidate-label scoring.
$ python -m pip install 'transformers[torch]==5.23.0'
from transformers import pipeline

classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli", device=-1)
print(classifier("Please reset my password", candidate_labels=["billing", "account"]))

Transformers examples

From open-source projects on GitHub

Provides a natural language toolkit.

Downloads / mo
48.7M
Stars
14.8K
Last release
3.10.4
License
Apache-2.0
$ python -m pip install nltk==3.10.4
from nltk.classify import NaiveBayesClassifier

training = [({"invoice": True}, "billing"), ({"password": True}, "account")]
classifier = NaiveBayesClassifier.train(training)
print(classifier.classify({"invoice": True}))

nltk examples

From open-source projects on GitHub

Processes natural language in Python.

Downloads / mo
25.2M
Stars
34.0K
Last release
3.8.18
License
MIT

Quickstart

From README.md
$ python -m pip install spacy==3.8.18
import spacy
from spacy.training import Example

nlp = spacy.blank("en")
nlp.add_pipe("textcat")
samples = [("invoice payment", {"billing": 1.0, "account": 0.0}),
           ("reset password", {"billing": 0.0, "account": 1.0})]
examples = [Example.from_dict(nlp.make_doc(text), {"cats": cats}) for text, cats in samples]
optimizer = nlp.initialize(get_examples=lambda: examples)
nlp.update(examples, sgd=optimizer)
print(nlp("invoice").cats)

spacy examples

From open-source projects on GitHub

Provides the CatBoost Python package.

Downloads / mo
6.9M
Stars
9.2K
Last release
1.2.10
License
Apache-2.0

Quickstart

From README.md
$ python -m pip install catboost==1.2.10
from catboost import CatBoostClassifier

texts = [["invoice payment"]] * 10 + [["password login"]] * 10
labels = ["billing"] * 10 + ["account"] * 10
model = CatBoostClassifier(iterations=5, text_features=[0], verbose=False)
model.fit(texts, labels)
print(model.predict([["invoice payment"]]))

catboost examples

From open-source projects on GitHub

Processes text with sentiment analysis, part-of-speech tagging, and noun phrase parsing.

Downloads / mo
3.2M
Stars
9.6K
Last release
0.20.1
License
MIT

Quickstart

From classifiers.html
$ python -m pip install textblob==0.20.1 && python -m textblob.download_corpora
from textblob.classifiers import NaiveBayesClassifier

training = [("invoice payment", "billing"), ("reset password", "account")]
classifier = NaiveBayesClassifier(training)
print(classifier.classify("invoice"))

textblob examples

From open-source projects on GitHub

Trains supervised text classifiers through train_supervised.

Downloads / mo
2.2M
Stars
26.5K
Last release
0.9.3
License
MIT

Strengths

  • Returns labels with probabilities. Use predict to retrieve labels and their corresponding probabilities.
  • Compresses trained classifier files. Quantize supervised models after training to reduce their stored size.

Limitations

  • Upstream repository is archived. The original repository is now read-only.
  • Needs labeled training examples. Supply documents with their corresponding category labels before training.

Quickstart

From README.md
$ python -m pip install fasttext==0.9.3
from pathlib import Path
from tempfile import TemporaryDirectory
import fasttext

with TemporaryDirectory() as directory:
    training = Path(directory) / "train.txt"
    training.write_text("__label__billing invoice payment\n__label__account reset password\n", encoding="utf-8")
    model = fasttext.train_supervised(str(training), minCount=1)
    print(model.get_labels())

fastText examples

From open-source projects on GitHub

Provides pretrained models for Keras.

Downloads / mo
471.7K
Stars
999
Last release
0.33.0
License
Apache-2.0

Quickstart

From README.md
$ python -m pip install keras-hub==0.33.0 tensorflow==2.21.0
import os
os.environ["KERAS_BACKEND"] = "tensorflow"
import tensorflow as tf
import keras_hub

training = tf.data.Dataset.from_tensor_slices(
    (["invoice payment", "reset password"], [0, 1])
).batch(2)
classifier = keras_hub.models.TextClassifier.from_preset("bert_tiny_en_uncased", num_classes=2)
classifier.fit(training, epochs=1)
print(classifier.predict(["invoice"]))

keras-hub examples

From open-source projects on GitHub
def preprocess(x, y=None, sequence_length=256):
    x = tokenizer(x)
    x = packer(x, sequence_length=sequence_length)
    x = {
        "token_ids": x,
        "padding_mask": x != tokenizer.pad_token_id,
    }
    return keras.utils.pack_x_y_sample_weight(x, y)

FAQ

scikit-learn suits pipelines that combine text features with a classifier and structured data. Transformers suits fine-tuned sequence classifiers and zero-shot labels chosen at prediction time. fastText suits compact supervised classifiers trained from labeled examples.

fastText trains supervised text classifiers that return labels with probabilities. It can compress trained classifier files, and its upstream repository is archived.

A zero-shot pipeline in Transformers scores candidate labels chosen at runtime. It needs a model fine-tuned for natural language inference rather than an arbitrary language model.

scikit-learn combines a text feature vectorizer with a classifier in one pipeline. Unigram bag-of-words features disregard word order.

For coding agents

Found your text classification library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official