torchTextClassifiers
A unified, extensible framework for text classification with categorical variables built on PyTorch and PyTorch Lightning.
🚀 Features
- Complex input support: Handle text data alongside categorical variables seamlessly.
- ValueEncoder: Pass raw string categorical values and labels directly — no manual integer encoding required. Build a
ValueEncoderfromDictEncoderor sklearnLabelEncoderinstances once, and the wrapper handles encoding at train time and label decoding after prediction automatically.
- ValueEncoder: Pass raw string categorical values and labels directly — no manual integer encoding required. Build a
- Unified yet highly customizable:
- Use any tokenizer from HuggingFace or the original fastText's ngram tokenizer.
- Text embedding is split into two composable stages:
TokenEmbedder(token → per-token vectors, with optional self-attention) andSentenceEmbedder(aggregation: mean / first / last / label attention). Combine them withCategoricalVariableNetandClassificationHead— all aretorch.nn.Module. - Two architecture paths: use
ModelConfig+ thetorchTextClassifiersconstructor for the standardTextClassificationModel(zero boilerplate), or build anynn.Moduleyou like and pass it totorchTextClassifiers.from_model()for full control. Thecontribsub-package ships ready-made custom architectures (e.g.MultiLevelTextClassificationModelfor multi-task classification) as reference implementations.
- Multiclass / multilabel classification support: Support for both multiclass (only one label is true) and multi-label (several labels can be true) classification tasks.
- PyTorch Lightning: Automated training with callbacks, early stopping, and logging
- Easy experimentation: Simple API for training, evaluating, and predicting with minimal code:
- The
torchTextClassifierswrapper class orchestrates the tokenizer and the model for you
- The
- Explainability:
- Captum integration: gradient-based token attribution via integrated gradients (
explain_with_captum=True). - Label attention: class-specific cross-attention that produces one sentence embedding per class, enabling token-level explanations for each label (
explain_with_label_attention=True). Enable it by settingn_heads_label_attentioninModelConfig.
- Captum integration: gradient-based token attribution via integrated gradients (
📦 Installation
# Clone the repository
git clone https://github.com/InseeFrLab/torchTextClassifiers.git
cd torchTextClassifiers
# Install with uv (recommended)
uv sync
# Or install with pip
pip install -e .
📖 Documentation
Full documentation is available at: https://inseefrlab.github.io/torchTextClassifiers/ The documentation includes:
- Getting Started: Installation and quick start guide
- Architecture: Understanding the 3-layer design
- Tutorials: Step-by-step guides for different use cases
- API Reference: Complete API documentation
📝 Usage
Checkout the notebook for a quick start.
📚 Examples
See the examples/ directory for:
- Basic text classification
- Multi-class classification
- Mixed features (text + categorical)
- Advanced training configurations
- Prediction and explainability
- Multi-level classification — custom architecture via
from_modelandcontrib
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for torchtextclassifiers 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| torchtextclassifiers-2.0.0.tar.gz | 37.6 kB | Without provenance | Details for torchtextclassifiers-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torchtextclassifiers-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for torchtextclassifiers-2.0.0-py3-none-any.whl |
Total release size: 85.3 kB
Release files / torchtextclassifiers-2.0.0.tar.gz
| Download URL | torchtextclassifiers-2.0.0.tar.gz |
|---|---|
| Size | 37.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43a48c3cecd4cd75aa4e2700dce5a7a8338ea8c0b58b1f5059c680f750e9f314
|
|
BLAKE2b-256 checksum How to use checksums |
ee5374b1251f016f1cdb9f995e3b219d94a93a50b7db5c1d08968254f056068a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / torchtextclassifiers-2.0.0-py3-none-any.whl
| Download URL | torchtextclassifiers-2.0.0-py3-none-any.whl |
|---|---|
| Size | 47.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd2f34db2f232ae3c0e14a08523612b156e298ab5f94922613851b8ada0560e6
|
|
BLAKE2b-256 checksum How to use checksums |
dcaa393555cb826afa01d91d8ac0329fda594caeea9744b8065f2aa93267292a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for torchtextclassifiers 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.