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.2.tar.gz (5.2 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.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: classifaier-0.1.2.tar.gz
  • Upload date:
  • Size: 5.2 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.2.tar.gz
Algorithm Hash digest
SHA256 008d2158deb6ce15e1da93fdd2fc62c941a65d30c3360dc024b2a4e0687f808d
MD5 c4bf035a7e13519976d231fdfd40b53e
BLAKE2b-256 79eba09eef3840d9c86a49228fedb3d1df0caecd7450462d286afc4c4a0cefb4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ClassifAIer-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a2b6b6b8d574b581bd6d4bb09f56ca58b2e760a4d7bb79bb089853a39a65b302
MD5 7f3b76c6d6f03f9a271a9dc69eab790e
BLAKE2b-256 cb51d92a187d143cea3a14101f1fe12dc82f3ee2b6a0133a3d3462fd8289bd29

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