Skip to main content

A Python package for text classification using transformer models.

Project description

TextPredict

python PyPI - Version Code style: black Ruff security: bandit Downloads

TextPredict Logo

Advanced Text Classification with Transformer Models

TextPredict is a powerful Python package designed for text classification tasks leveraging advanced transformer models. It supports a variety of tasks including sentiment analysis, emotion detection, and zero-shot classification, making it an essential tool for developers and data scientists working in natural language processing (NLP), machine learning (ML), and artificial intelligence (AI).

Features

  • Sentiment Analysis: Classify text based on sentiment with high accuracy.
  • Emotion Detection: Detect emotions in text effortlessly.
  • Zero-Shot Classification: Classify text into unseen categories without any additional training.
  • Fine-Tuning: Easily fine-tune models to improve performance on specific datasets.
  • Model Evaluation: Evaluate model performance with robust metrics.
  • Distributed Training: Support for distributed training to leverage multiple GPUs.

Installation

pip install textpredict

Usage

Sentiment Analysis

from textpredict import TextPredict

tp = TextPredict()
result = tp.analyse("I love using this package!", task="sentiment")
print(result)

Emotion Detection

result = tp.analyse("I am excited about this!", task="emotion")
print(result)

Zero-Shot Classification

result = tp.analyse(
    "This package is great for zero-shot learning.",
    task="zeroshot",
    class_list=["positive", "negative", "neutral"],
)
print(result)

Fine-Tuning Models

from datasets import load_dataset

# Load dataset
dataset = load_dataset("imdb")

# Fine-tune model
tp.tune_model(
    task="sentiment",
    training_data=dataset["train"],
    eval_data=dataset["test"],
    num_train_epochs=1,
    batch_size=8,
    learning_rate=2e-5,
    early_stopping_patience=3,
)

Evaluating Models

metrics = tp.evaluate_model(task="sentiment", eval_data=dataset["test"])
print("Evaluation metrics:", metrics)

Saving and Loading Models

tp.save_model(task="sentiment", output_dir="./fine_tuned_sentiment_model")
tp.load_model(task="sentiment", model_dir="./fine_tuned_sentiment_model")
result = tp.analyse("I love using this package after fine-tuning!", task="sentiment")
print(result)

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Links

Project details


Download files

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

Source Distribution

textpredict-0.1.2.tar.gz (17.0 kB view hashes)

Uploaded Source

Built Distribution

textpredict-0.1.2-py3-none-any.whl (24.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page