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

  • 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
  • Optional ONNX export and ONNX Runtime prediction backend for production inference deployment
  • 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.

[!TIP]

Using uv?

To install into an existing uv-managed environment, use:

uv pip install "tlmtc[train]"

If you are adding tlmtc as a dependency to a uv-managed Python project, use:

uv add "tlmtc[train]"
Installing from source?

Install the latest development version directly from GitHub:

pip install "tlmtc[train] @ git+https://github.com/saschagobel/tlmtc.git"

With uv, install into the active environment with:

uv pip install "tlmtc[train] @ git+https://github.com/saschagobel/tlmtc.git"

Or add it to a uv-managed project:

uv add "tlmtc[train] @ 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.

[!TIP]

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(
    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.

[!TIP]

Prefer the CLI?
tlmtc train \
  --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

tlmtc predict \
  --unlabeled-data paired_example_unlabeled.csv \
  --use-cpu
Try your own data

Your labeled data must include:

  • a text column
  • 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 unlabeled data 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tlmtc-0.4.1.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tlmtc-0.4.1-py3-none-any.whl (63.9 kB view details)

Uploaded Python 3

File details

Details for the file tlmtc-0.4.1.tar.gz.

File metadata

  • Download URL: tlmtc-0.4.1.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tlmtc-0.4.1.tar.gz
Algorithm Hash digest
SHA256 80227b312d767a807b8f2589aaff2081cd76c1e0fd482956f8264489c4f27754
MD5 edeba75a9373c74e1ca36fa4b2f4bfb7
BLAKE2b-256 e0c96c3d80833b40e4ca6b9b049bb90484676e5ed6defbfeaf54bbe16dc317a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tlmtc-0.4.1.tar.gz:

Publisher: release.yml on saschagobel/tlmtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tlmtc-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: tlmtc-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 63.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tlmtc-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a50e7c852a5796d7a7d2b8044d23aa2efa826a889460e579b12faf7650fb49af
MD5 e594e86b8ec7e7255f01f8e482a3e2ab
BLAKE2b-256 a38f990f4239ae10295ec217ecd57341ae60506a81664743677dda21c4ff5ae4

See more details on using hashes here.

Provenance

The following attestation bundles were made for tlmtc-0.4.1-py3-none-any.whl:

Publisher: release.yml on saschagobel/tlmtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.4.2

2 files

This release

0.4.1 This release

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

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