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
positive_prediction = classifier.predict("I love this product!")
print(positive_prediction)  # Output: 'positive'

negative_prediction = classifier.predict("I hate this service.")
print(negative_prediction)  # Output: 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.4.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.4-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file ClassifAIer-0.1.4.tar.gz.

File metadata

  • Download URL: ClassifAIer-0.1.4.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for ClassifAIer-0.1.4.tar.gz
Algorithm Hash digest
SHA256 7a84872270d73ea7217df7f05ee4e04edd4cbbeba2ee0b48732004f59b921ccd
MD5 5aa9511b95d956f87a137f00cc2b538e
BLAKE2b-256 ce33b294ed7e51f7ac7ada039fc8d0e7671a299fe6a41eab2e9e1bf702db26a5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ClassifAIer-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ebb17a3cfd4f31e5ad7d7355f2ec6a8f5dba6fe2fad17c08535b4ba98dc96cfc
MD5 2267f675a89a7801751e833e23271d0a
BLAKE2b-256 5c2a1b80659e7279b391d402487be67f42fdcd99f4a9d04a79aa0842078eaf0d

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