Production Workflows for Transformer-based Multi-label Text Classification
Project description
tlmtc (Transfer Learning for Multi-label Text Classification) is an opinionated Python package that provides production-ready, end-to-end workflows for fine-tuning pretrained encoder-only transformer models for robust multi-label text classification.
In applied settings, text classification is rarely a simple single-label task or a mutually exclusive multiclass problem. A clinical note may map to several ICD codes at once. A customer-support ticket can span multiple issue categories for routing, prioritization, and analytics. A contract may contain several clause types, and a litigation document can raise multiple legal issues. In RAG and LLM evaluation, a single answer may need several concurrent quality labels. A threat-intelligence report can mention multiple tactics, techniques, and vulnerabilities in the same document. Across domains, useful text labels often overlap, co-occur, and vary in prevalence.
tlmtc turns these use cases into repeatable training and prediction workflows. It prepares multi-label text data, fine-tunes transformer classifiers, tunes hyperparameters and decision thresholds, evaluates model performance, writes reports, and applies trained models to new data — all exposed through a small workflow-oriented API.
Key features
- Parameter-efficient fine-tuning via LoRA (PEFT), with optional full fine-tuning
- Automatic detection of single-text and paired-text inputs for encoder and cross-encoder-style classification
- Customizable Optuna-based hyperparameter tuning, optionally on a smaller proxy model for efficiency
- Carry-over from proxy to larger target model with optional automatic learning-rate scaling
- Global and label-specific threshold optimization for calibrated multi-label decisions
- Iterative stratified data splitting for multi-label datasets, with automatic group-aware splitting
- Custom class-weighted loss for handling label imbalance
- Comprehensive evaluation suite with global and label-specific multi-label metrics
- Publication-ready reporting through tables and graphs
- End-to-end prediction workflow that reloads trained models, metadata, labels, and thresholds automatically
- Automatic persistence and reuse of data splits, Optuna studies, trained models, thresholds, and run metadata
- Highly configurable through a small workflow-oriented Python API and CLI
- CPU and multi-GPU training and prediction support
Installation
We recommend installing tlmtc in a dedicated uv environment with the full extra:
uv add "tlmtc[full]"
The full extra installs the optional deep-learning dependencies required for training and prediction, including PyTorch, PEFT, and Accelerate.
Using pip?
pip install "tlmtc[full]"
Installing from source?
uv add "tlmtc[full] @ git+https://github.com/saschagobel/tlmtc.git"
Or with pip:
pip install "tlmtc[full] @ git+https://github.com/saschagobel/tlmtc.git"
Quickstart
This quickstart uses a small synthetic paired-text dataset included in the repository. It mimics a requirements-engineering setting, where requirement records are paired with validation, commissioning, configuration, or field-service evidence and labeled for multiple concurrent issues. You will fine-tune a multi-label classifier and then apply the trained model to unlabeled examples.
Create a working directory and download the example data:
mkdir tlmtc-quickstart
cd tlmtc-quickstart
curl -L -o paired_example.csv \
https://raw.githubusercontent.com/saschagobel/tlmtc/main/examples/paired_example.csv
curl -L -o paired_example_unlabeled.csv \
https://raw.githubusercontent.com/saschagobel/tlmtc/main/examples/paired_example_unlabeled.csv
The code below assumes that both CSV files are in your current working directory. If you save them somewhere else, adjust the file paths accordingly.
Using Windows PowerShell?
New-Item -ItemType Directory -Force -Path tlmtc-quickstart
Set-Location tlmtc-quickstart
Invoke-WebRequest `
-Uri "https://raw.githubusercontent.com/saschagobel/tlmtc/main/examples/paired_example.csv" `
-OutFile "paired_example.csv"
Invoke-WebRequest `
-Uri "https://raw.githubusercontent.com/saschagobel/tlmtc/main/examples/paired_example_unlabeled.csv" `
-OutFile "paired_example_unlabeled.csv"
Fine-tune a model:
from tlmtc import train_tlmtc
train_tlmtc(
"paired_example.csv",
target_name="Requirements Evidence Alignment",
checkpoint="google/bert_uncased_L-2_H-128_A-2",
tuning_trials=5,
use_cpu=True,
)
This quickstart intentionally uses a tiny model and only five HPO trials to keep the demo lightweight.
Use your fine-tuned model to run prediction on unlabeled data:
from tlmtc import predict_tlmtc
predict_tlmtc(
"paired_example_unlabeled.csv",
use_cpu=True,
)
tlmtc writes training artifacts to train_outputs/ and prediction artifacts to prediction_outputs/. Evaluation reports are written to train_outputs/<run_id>/evaluation/.
Prefer the CLI?
tlmtc train \
--raw-csv paired_example.csv \
--target-name "Requirements Evidence Alignment" \
--checkpoint google/bert_uncased_L-2_H-128_A-2 \
--tuning-trials 5 \
--use-cpu
tlmtc predict \
--prediction-csv paired_example_unlabeled.csv \
--use-cpu
Try your own data
Your training CSV must include:
- a
textcolumn - at least two binary
label_-prefixed columns
Add a text_pair column for paired-input classification. tlmtc detects and handles this automatically.
Add a split_group column when semantically related rows must not cross train, validation, and test splits.
For prediction, provide an unlabeled CSV with the same input columns used during training. For a paired-text model, this means both text and text_pair.
Contributing
Contributions are welcome. Please read CONTRIBUTING.md before opening an issue or pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tlmtc-0.2.0.tar.gz.
File metadata
- Download URL: tlmtc-0.2.0.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aabedf472e9d0c5b7f32a86f62930a7bb7299c043cc89308ffb0aff8d057b949
|
|
| MD5 |
0b475b143b841210eadce3b8199cc6d6
|
|
| BLAKE2b-256 |
70f671063631507f302f0a7e6ad538e1b5a66cdfd2751b92f8308f998bae1334
|
Provenance
The following attestation bundles were made for tlmtc-0.2.0.tar.gz:
Publisher:
release.yml on saschagobel/tlmtc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tlmtc-0.2.0.tar.gz -
Subject digest:
aabedf472e9d0c5b7f32a86f62930a7bb7299c043cc89308ffb0aff8d057b949 - Sigstore transparency entry: 1575050883
- Sigstore integration time:
-
Permalink:
saschagobel/tlmtc@aead288e646ac6b2279ca3baa866c2b7ff665e06 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/saschagobel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@aead288e646ac6b2279ca3baa866c2b7ff665e06 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tlmtc-0.2.0-py3-none-any.whl.
File metadata
- Download URL: tlmtc-0.2.0-py3-none-any.whl
- Upload date:
- Size: 51.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a21baadad670d482e78a42753a10013062a5ebd8d41b98ade048fd9308d8e82
|
|
| MD5 |
5bafeda512837289e358fece655173fd
|
|
| BLAKE2b-256 |
d720cb92e7299b5b93f3d240bffb374418b96c83b98a38b9e67f465ecde1acf7
|
Provenance
The following attestation bundles were made for tlmtc-0.2.0-py3-none-any.whl:
Publisher:
release.yml on saschagobel/tlmtc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tlmtc-0.2.0-py3-none-any.whl -
Subject digest:
9a21baadad670d482e78a42753a10013062a5ebd8d41b98ade048fd9308d8e82 - Sigstore transparency entry: 1575050914
- Sigstore integration time:
-
Permalink:
saschagobel/tlmtc@aead288e646ac6b2279ca3baa866c2b7ff665e06 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/saschagobel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@aead288e646ac6b2279ca3baa866c2b7ff665e06 -
Trigger Event:
push
-
Statement type: