Skip to main content

A library for text classification using LangChain embeddings and scikit-learn classifiers.

Project description

ClassifAIer

ClassifAIer is a Python library that combines scikit-learn classifiers with LangChain embedding libraries, enabling seamless text classification using embeddings from large language models. This library offers a user-friendly interface, allowing you to classify text data in a human-like manner.

Features

  • Embedding Support: Ability to work with embeddings from large language models like OpenAI and compatible with embeddings supported by LangChain.
  • Parametric Classifiers: Compatibility with a wide range of classifiers from scikit-learn (e.g., RandomForestClassifier, KNeighborsClassifier, etc.).
  • Easy to Use: Simplifies text classification tasks with a user-friendly API.
  • Save and Load: Allows you to save and reload trained models for reuse.

Requirements

To use this library, you need Python 3.7 or higher. The required packages will be automatically installed when you install this library.

  • scikit-learn
  • langchain-core
  • langchain
  • numpy

Installation

You can install the required libraries using the following command:

pip install ClassifAIer

Usage

from classifaier import ClassifAIer
from langchain.embeddings import OpenAIEmbeddings

# Initialize the embedding provider
embedding_provider = OpenAIEmbeddings(api_key='YOUR_API_KEY')

random_forest_classifier_params = {
    "n_estimators": 100,
    "max_depth": None,
    "min_samples_split": 2,
    "min_samples_leaf": 1,
    "random_state": 42
}

random_forest_classifier = RandomForestClassifier(**random_forest_classifier_params)

# Create a classifier instance
classifier = ClassifAIer(embedding_provider=embedding_provider, classifier=random_forest_classifier)

# Prepare your data
texts = ["This is a positive review.", "This is a negative review."]
labels = ["positive", "negative"]

# Train the model
classifier.fit(texts, labels)

# Make predictions
predictions = classifier.predict(["I love this product!", "I hate this service."])
print(predictions)  # Output: ['positive', 'negative']

# Save the model
classifier.save("my_classifier.pkl")

# Load the model
loaded_classifier = ClassifAIer.load("my_classifier.pkl", embedding_provider)

Contributing

Contributions are welcome! If you have suggestions or improvements, please create a pull request or open an issue.

License

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

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

classifaier-0.1.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

ClassifAIer-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file classifaier-0.1.1.tar.gz.

File metadata

  • Download URL: classifaier-0.1.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.1

File hashes

Hashes for classifaier-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fd25aec279715b262e965800273130d58d71f36d5f6f3f6c808dc0bb9d626be6
MD5 f8b8b99ef410b554e5b7288bc4cd8107
BLAKE2b-256 24808b835cb48d8c741008f62f621894333aa0836f96827745942754d5b08ab5

See more details on using hashes here.

File details

Details for the file ClassifAIer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ClassifAIer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.1

File hashes

Hashes for ClassifAIer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b23ad5eb472aaf13c32137ae77995a6d2b41d34cb474e25c7e1da994141de4f
MD5 58d5a06d91c6349e8d99c7308e0a6f4e
BLAKE2b-256 428f75b40ab186271ca615019c76fe386d48282d62d86b326ab88dee0191a891

See more details on using hashes here.

Supported by

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