webis-de/small-text
Active Learning for Text Classification in Python
small‑text – Active Learning for Text Classification
What it is
- A Python library that implements active learning workflows for text classification. It lets you start with very few labeled examples, train a classifier, query the most informative unlabeled documents, label them, and repeat until a stopping condition is met.
Key capabilities
| Capability | Details |
|---|---|
| Query strategies | 19 built‑in methods (e.g., uncertainty, diversity, margin, entropy, SetFit‑based) that decide which unlabeled texts to ask a human annotator to label. |
| Initialization | Several ways to bootstrap the first labeled set, including random, clustering‑based, and zero‑shot SetFit initialization. |
| Stopping criteria | 5 ready‑to‑use criteria (budget, performance plateau, confidence thresholds, etc.) to automatically end the active‑learning loop. |
| Classifier back‑ends | Works with any scikit‑learn estimator, PyTorch models, and Hugging Face transformers. GPU support is optional; a lightweight CPU‑only install is also available. |
| Extensibility | Interfaces are deliberately modular so you can mix any query strategy, classifier, and stopping rule. |
Typical workflow
- Install –
pip install small-text(add[transformers]extra for transformer models). - Prepare data – supply a pool of unlabeled texts and (optionally) a small seed set of labels.
- Choose components – pick a classifier (e.g.,
sklearn.LinearSVC, atorch.nn.Module, or atransformersmodel), a query strategy, and a stopping criterion. - Run the loop – the library handles training, querying, and updating the labeled set automatically.
- Export – retrieve the final trained model or the labeled dataset for downstream use.
Why it matters
- Label efficiency – reduces the amount of manual annotation needed for high‑quality text classifiers, which is especially valuable in domains where labeling is costly (biomedicine, social science, legal text, etc.).
- Research‑ready – the library is used in several peer‑reviewed studies and includes reproducibility notes, making it suitable for academic experiments.
- Integration friendly – can be combined with UI tools like Argilla for a full annotation interface, or embedded in custom pipelines.
Getting started
- The repository ships example scripts for binary classification, PyTorch multi‑class, and transformer‑based multi‑class setups.
- Five Jupyter notebooks (available on GitHub and launchable in Google Colab) walk you through an end‑to‑end active‑learning session, stopping‑criteria usage, SetFit integration, zero‑shot cold‑start, and a UI demo with Argilla.
Documentation & community
- Full docs at https://small-text.readthedocs.io covering installation, component reference, reproducibility notes, and a showcase of real‑world applications.
- The project is actively maintained (MIT‑licensed), has CI badges, a DOI for citation, and welcomes contributions via a CONTRIBUTING guide.
When to use it
- You have a large corpus of texts but only a handful of labeled examples.
- You want to experiment with different active‑learning strategies without writing boiler‑plate code.
- You need a library that works with both classic ML models and modern transformer models.
small‑text is therefore a genuine, actively maintained software project focused on a core machine‑learning technique (active learning) for text data, fitting squarely within the AI/ML ecosystem.
Related
- Project
- Project
- Project
- Project