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, the following packages must be installed:

  • Python 3.7+
  • scikit-learn
  • langchain
  • numpy

Installation

You can install the required libraries using the following command:

pip install scikit-learn langchain numpy

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.0.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.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: classifaier-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 17a279b2c1138e94852ff604de3c4d975ab0dfc6f63200c13bdfa4594d18c5f3
MD5 6ba66b071c63a30a637220faab02611c
BLAKE2b-256 8ed8cb4ac1ecf71a2a0fb856761cf55debb1417115517d157aa5c2d86ee7eb1a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ClassifAIer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 088d4a377f12728f58f96a0032854aa580fc680562548aac2a69b61c7f47e4e8
MD5 40d92f0eef318ee9fdd5d56c54d47611
BLAKE2b-256 c0a154e349329ab03ded5d0330cf2289c869a8c571a18583bfdbde1e0c73044d

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