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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file classifaier-0.1.3.tar.gz.
File metadata
- Download URL: classifaier-0.1.3.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
045b3427a4195687979dc3b2d94db5ef797883bebb0d9e86d15a05bb193164b4
|
|
| MD5 |
df5c44fd3541fadddd8bab56fc9be8ce
|
|
| BLAKE2b-256 |
236400cc9ba6353e500cbee0e90906a71199e2252f57859b06d78cbcf22c77a8
|
File details
Details for the file ClassifAIer-0.1.3-py3-none-any.whl.
File metadata
- Download URL: ClassifAIer-0.1.3-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed311e6c70cef6b819f43888550260497856cba30ef76e721efba47ec9a0fcee
|
|
| MD5 |
5e9e5af6cc7c9d05c1e6130e10abffd0
|
|
| BLAKE2b-256 |
2805515b80c84bb4f09a66f93f82797a0e426a7b2763f4e9b0b359dd2653350f
|