Skip to main content

tlmtc: Transfer Learning for Multi-label Text Classification

License CI PyPI Python versions

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

Data preparation

  • Automatic detection of single-text and paired-text inputs for encoder and cross-encoder-style classification
  • Iterative stratified data splitting for multi-label datasets, with automatic group-aware splitting

Training and optimization

  • Parameter-efficient fine-tuning via LoRA, with optional full fine-tuning
  • 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
  • Custom class-weighted loss for handling label imbalance
  • Global and label-specific decision threshold optimization

Evaluation and reporting

  • Comprehensive evaluation suite with global and label-specific multi-label metrics
  • Publication-ready reporting through tables and graphs

Prediction

  • End-to-end prediction workflow that reloads trained models, metadata, labels, and thresholds automatically
  • Optional ONNX export and ONNX Runtime prediction backend for production inference deployment

Deployment and operations

  • Docker images for GPU hyperparameter tuning, GPU training, and CPU ONNX prediction
  • Terraform configurations and runner scripts for Azure VM deployments
  • 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 DDP-safe multi-GPU training and prediction support

Installation

Install tlmtc into your active Python environment with the train extra:

pip install "tlmtc[train]"

The train extra installs the dependencies required for the full training workflow and includes the Torch-backed prediction runtime.

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.

Fine-tune a model:

from tlmtc import train_tlmtc

train_tlmtc(
    labeled_data="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/.

For production inference, the optional onnx-export and onnx-runtime installation extras provide the dependencies for exporting trained models to ONNX and running the ONNX Runtime prediction backend, respectively.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md before opening an issue or pull request.

Metadata

Release files for tlmtc 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tlmtc 0.5.0
File Size Uploaded Provenance Actions
tlmtc-0.5.0.tar.gz 1.3 MB With provenance Details for tlmtc-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tlmtc 0.5.0
File Interpreter ABI Platform Actions
tlmtc-0.5.0-py3-none-any.whl Python 3 none any Details for tlmtc-0.5.0-py3-none-any.whl

Total release size: 1.4 MB

Release files / tlmtc-0.5.0.tar.gz

Download URL tlmtc-0.5.0.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
98ba7c865744b489c4c1ab8a627dbf02046243ee2571cf5847b2e66cb5c41b73
BLAKE2b-256 checksum
How to use checksums
0eadefd5d65f781c6fae67ab4421da9eb62a19aeb81567cccd3f4c9654c14eec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / tlmtc-0.5.0-py3-none-any.whl

Download URL tlmtc-0.5.0-py3-none-any.whl
Size 64.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4942e7f38e86998b23620826026dac64ee0ad5863c9d6d675bfee6f3c11a780c
BLAKE2b-256 checksum
How to use checksums
f1cbc71e7d899932e3804522e25b9608ef536002868885c99b06fd589baed1b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for tlmtc 0.5.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tlmtc-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page