Skip to main content

RapidFit

Turn a handful of labeled examples into a production-ready multi-task classifier.

RapidFit handles the two biggest pain points in text classification: not enough data and too many separate models. Give it a few examples per class, and it will generate more training data using LLMs, then train a single model that handles all your classification tasks at once.

Installation

pip install rapidfit

Annotate Unlabeled Data

Have raw texts but no labels? Use LLMAnnotator to get LLM-generated labels, then expand with augmentation.

from rapidfit import LLMAnnotator, LLMAugmenter, MultiheadClassifier

# Define your tasks and labels
tasks = [
    {
        "name": "sentiment",
        "labels": ["positive", "negative", "neutral"],
        "instruction": "Judge by overall tone, not individual words"
    },
    {
        "name": "urgency",
        "labels": ["urgent", "normal", "low"]
    },
]

# Your unlabeled texts
texts = [
    "This product exceeded my expectations!",
    "Need immediate assistance with my order",
    "Just browsing, thanks.",
]

# Annotate with LLM
annotator = LLMAnnotator(api_key="your-api-key")
labeled_data = annotator.annotate(texts, tasks)

# Option 1: Expand with augmentation first
augmenter = LLMAugmenter(api_key="your-api-key", max_samples_per_task=128)
augmented = augmenter.augment(labeled_data)

# Option 2: Train directly on annotated data
classifier = MultiheadClassifier()
classifier.train(labeled_data)
Parameter Default Description
model_id gpt-4.1-mini LLM to use for annotation
batch_size 16 Texts per annotation call
temperature 0.3 Lower for consistent labels
save_path ./saved Output directory
save_format jsonl Format: json, jsonl, or csv
fix_empty_labels False Synthesize samples for labels with no data
min_samples_per_label 16 Minimum synthesized per empty label

For the complete annotation workflow including label hints and synthesis options, see Annotation Guide.

Augment Your Data

Start with just a few examples. RapidFit uses LLMs to expand your dataset while preserving label quality.

from rapidfit import LLMAugmenter

seed_data = {
    "sentiment": [
        {"text": "I love this product!", "label": "positive"},
        {"text": "Terrible experience.", "label": "negative"},
    ],
    "emotion": [
        {"text": "This makes me so happy!", "label": "joy"},
        {"text": "I can't believe they did this.", "label": "anger"},
    ],
}

augmenter = LLMAugmenter(api_key="your-api-key")
augmented = augmenter.augment(seed_data)

Configure generation with optional parameters:

Parameter Default Description
model_id gpt-4.1-mini LLM to use for generation
max_samples_per_task 128 Target samples per task
batch_size 8 Samples per generation call
save_path ./saved Output directory
save_format json Format: json, jsonl, or csv
write_mode overwrite overwrite or append to existing data

When using append mode, RapidFit loads existing data from the save path and skips duplicate texts during generation.

Analyze and Clean Your Data

Before training, check your dataset for quality issues:

from rapidfit import DatasetAnalyzer, DatasetRefiner, RefinementConfig

# Analyze: detect imbalance, outliers, duplicates
analyzer = DatasetAnalyzer()
report = analyzer.analyze(seed_data)

# Refine: fix issues
refiner = DatasetRefiner(RefinementConfig(
    max_per_label=100,
    remove_duplicates=True,
))
cleaned = refiner.refine(seed_data)
Parameter Default Description
imbalance_ratio 0.1 Flag labels below this ratio of largest
max_per_label None Cap samples per label
remove_short False Remove short text outliers
remove_duplicates True Remove duplicate texts

For the complete analysis workflow, see Dataset Analysis Guide.

Train a Classifier

One model, multiple tasks. The multihead architecture shares a single encoder across all your classification tasks, making it efficient and consistent.

from rapidfit import MultiheadClassifier

classifier = MultiheadClassifier()
classifier.train(augmented)
classifier.save("./model")

Or train directly from a saved data directory:

classifier = MultiheadClassifier()
classifier.train(data_save_dir="./saved")
classifier.save("./model")

Customize training:

from rapidfit import MultiheadConfig, TrainingConfig, LossConfig

config = MultiheadConfig(
    training=TrainingConfig(epochs=10, learning_rate=2e-5),
    loss=LossConfig(use_class_weights=True),
)
classifier = MultiheadClassifier(config)

For a complete guide on configuration options and use cases, see How the Multihead Classifier Works.

Predict

classifier = MultiheadClassifier()
classifier.load("./model")

# Single task
classifier.predict(["Great product!"], task="sentiment")
# [{"label": "positive", "confidence": 0.95}]

# All tasks
classifier.predict_all_tasks(["Great product!"])

Error Analysis

Understand where your model fails before deploying:

result = classifier.analyze()       # Analyze test set
classifier.display(result)          # Show confusion matrix, metrics, errors

Get per-class precision/recall, confusion matrices, and the actual samples that were misclassified. See Error Analysis Guide for details.

Production Deployment

Export to ONNX for faster inference:

pip install rapidfit[export]
# Export with INT8 quantization (3-4x faster, 4x smaller)
classifier.export_onnx("./onnx_models", quantize=True)

For deployment strategies, ONNX Runtime usage, and performance optimization, see Inference Guide.

Extend It

Build custom augmenters or classifiers by extending the base classes:

from rapidfit import BaseAugmenter, BaseClassifier

License

MIT

Metadata

Release files for rapidfit 0.1.8

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

Source distribution (sdist)

Source distribution for rapidfit 0.1.8
File Size Uploaded Provenance Actions
rapidfit-0.1.8.tar.gz 35.5 kB Without provenance Details for rapidfit-0.1.8.tar.gz

Built distribution (wheel)

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

Total release size: 80.0 kB

Release files / rapidfit-0.1.8.tar.gz

Download URL rapidfit-0.1.8.tar.gz
Size 35.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1f712f5ea3e477b72faaa8cb061c67f8db930495b5befb671897871a64a4fd6d
BLAKE2b-256 checksum
How to use checksums
9d23b68d89fda865c84fd1b4df3dfe70747b0081e8c7d85745205d0ca3a4c33b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / rapidfit-0.1.8-py3-none-any.whl

Download URL rapidfit-0.1.8-py3-none-any.whl
Size 44.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d4cf17b395cb33dc2f9a6cb739655a800f9c08e82dc5377903628a4c1b111ce
BLAKE2b-256 checksum
How to use checksums
981b12f6e00bf30479baa34720c30c30f58866d777ff21c9a9639d5e598e0d78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Security for rapidfit 0.1.8

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.

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