[![python](https://img.shields.io/badge/Python-3.9|3.10|3.11|3.12|3.13-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org) ![PyPI - Version](https://img.shields.io/pypi/v/sentimentpredictor) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit) [![Downloads](https://static.pepy.tech/badge/sentimentpredictor)](https://pepy.tech/project/sentimentpredictor)
# Sentiment Analysis Predictor
![Emotion Classifier Logo](https://raw.githubusercontent.com/ankit-aglawe/sentimentpredictor/main/assets/logo.png)
A flexible sentiment analysis predictor package supporting multiple pre-trained models, customizable preprocessing, visualization tools, fine-tuning capabilities, and seamless integration with pandas DataFrames.
## Overview
`sentimentpredictor` is a Python package designed to classify sentiments in text using various pre-trained models from Hugging Face's Transformers library. This package provides a user-friendly interface for sentiment classification, along with tools for data preprocessing, visualization, fine-tuning, and integration with popular data platforms.
## Features
- **Multiple Model Support**: Easily switch between different pre-trained models.
- **Customizable Preprocessing**: Clean and preprocess text data with customizable functions.
- **Visualization Tools**: Visualize sentiment distributions and trends over time.
- **Fine-tuning Capability**: Fine-tune models on your own datasets.
- **User-friendly CLI**: Command-line interface for quick sentiment classification.
- **Integration with Data Platforms**: Seamless integration with pandas DataFrames.
- **Extended Post-processing**: Additional utilities for detailed sentiment analysis.
## Installation
You can install the package using pip:
```bash
pip install sentimentpredictor
```
## Usage
### Basic Usage
Here's an example of how to use the `SentimentPredictor` to classify a single text:
```python
from sentimentpredictor import SentimentPredictor
# Initialize the predictor with the default model
predictor = SentimentPredictor()
# Classify a single text
text = "I am very happy today!"
result = predictor.predict(text)
print("Sentiment:", result['label'])
print("Confidence:", result['confidence'])
```
### Batch Processing
You can classify multiple texts at once using the `predict_batch` method:
```python
texts = ["I am very happy today!", "I am so sad."]
results = predictor.predict_batch(texts)
print("Batch processing results:", results)
```
### Visualization
To visualize the sentiment distribution of a text:
```python
from sentimentpredictor import plot_sentiment_distribution
result = predictor.predict("I am very happy today!")
plot_sentiment_distribution(result['probabilities'], predictor.labels.values())
```
### CLI Usage
You can also use the package from the command line:
```bash
sentimentpredictor --model roberta --text "I am very happy today!"
```
### DataFrame Integration
Integrate with pandas DataFrames to classify text columns:
```python
import pandas as pd
from sentimentpredictor import DataFrameSentimentPredictor
df = pd.DataFrame({
'text': ["I am very happy today!", "I am so sad."]
})
predictor = DataFrameSentimentPredictor()
df = predictor.classify_dataframe(df, 'text')
print(df)
```
### Sentiment Trends Over Time
Analyze and plot sentiment trends over time:
```python
from sentimentpredictor import SentimentAnalysisTrends
texts = ["I am very happy today!", "I am feeling okay.", "I am very sad."]
trends = SentimentAnalysisTrends()
sentiments = trends.analyze_trends(texts)
trends.plot_trends(sentiments)
```
### Fine-tuning
Fine-tune a pre-trained model on your own dataset:
```python
from sentimentpredictor.fine_tune import fine_tune_model
# Define your train and validation datasets
train_dataset = ...
val_dataset = ...
# Fine-tune the model
fine_tune_model(predictor.model, predictor.tokenizer, train_dataset, val_dataset, output_dir='fine_tuned_model')
```
### Logging Configuration
By default, the `sentimentpredictor` package logs messages at the `WARNING` level and above. If you need more detailed logging (e.g., for debugging), you can set the logging level to `INFO` or `DEBUG`:
```python
from sentimentpredictor.logger import set_logging_level
# Set logging level to INFO
set_logging_level('INFO')
# Set logging level to DEBUG
set_logging_level('DEBUG')
```
You can set the logging level to one of the following: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`.
### Running Tests
Run the tests using pytest:
```bash
poetry run pytest
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgements
This package uses pre-trained models from the [Hugging Face Transformers library](https://github.com/huggingface/transformers).
## Contributing
Contributions are welcome! Please see the [CONTRIBUTING](CONTRIBUTING.md) file for guidelines on how to contribute to this project.
## Links
- [Documentation](https://github.com/ankit-aglawe/sentimentpredictor#readme)
- [PyPI](https://pypi.org/project/sentimentpredictor/)
- [Source Code](https://github.com/ankit-aglawe/sentimentpredictor)
- [Issue Tracker](https://github.com/ankit-aglawe/sentimentpredictor/issues)
Raw data
{
"_id": null,
"home_page": "https://github.com/ankit-aglawe/sentimentpredictor",
"name": "sentimentpredictor",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "sentiment analysis, text analysis, machine learning, NLP, transformers, data science, pre-trained models, text mining",
"author": "ankit-aglawe",
"author_email": "aglawe.ankit@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/da/9a/56da7fc17dc06786cdbff5510e1c5331ee6ec6a8ce247eeb038b96adf9e6/sentimentpredictor-0.1.3.tar.gz",
"platform": null,
"description": "[![python](https://img.shields.io/badge/Python-3.9|3.10|3.11|3.12|3.13-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org) ![PyPI - Version](https://img.shields.io/pypi/v/sentimentpredictor) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit) [![Downloads](https://static.pepy.tech/badge/sentimentpredictor)](https://pepy.tech/project/sentimentpredictor)\n\n# Sentiment Analysis Predictor\n\n![Emotion Classifier Logo](https://raw.githubusercontent.com/ankit-aglawe/sentimentpredictor/main/assets/logo.png)\n\n\nA flexible sentiment analysis predictor package supporting multiple pre-trained models, customizable preprocessing, visualization tools, fine-tuning capabilities, and seamless integration with pandas DataFrames.\n\n## Overview\n\n`sentimentpredictor` is a Python package designed to classify sentiments in text using various pre-trained models from Hugging Face's Transformers library. This package provides a user-friendly interface for sentiment classification, along with tools for data preprocessing, visualization, fine-tuning, and integration with popular data platforms.\n\n## Features\n\n- **Multiple Model Support**: Easily switch between different pre-trained models.\n- **Customizable Preprocessing**: Clean and preprocess text data with customizable functions.\n- **Visualization Tools**: Visualize sentiment distributions and trends over time.\n- **Fine-tuning Capability**: Fine-tune models on your own datasets.\n- **User-friendly CLI**: Command-line interface for quick sentiment classification.\n- **Integration with Data Platforms**: Seamless integration with pandas DataFrames.\n- **Extended Post-processing**: Additional utilities for detailed sentiment analysis.\n\n## Installation\n\nYou can install the package using pip:\n\n```bash\npip install sentimentpredictor\n```\n\n## Usage\n\n### Basic Usage\n\nHere's an example of how to use the `SentimentPredictor` to classify a single text:\n\n```python\nfrom sentimentpredictor import SentimentPredictor\n\n# Initialize the predictor with the default model\npredictor = SentimentPredictor()\n\n# Classify a single text\ntext = \"I am very happy today!\"\nresult = predictor.predict(text)\nprint(\"Sentiment:\", result['label'])\nprint(\"Confidence:\", result['confidence'])\n```\n\n### Batch Processing\n\nYou can classify multiple texts at once using the `predict_batch` method:\n\n```python\ntexts = [\"I am very happy today!\", \"I am so sad.\"]\nresults = predictor.predict_batch(texts)\nprint(\"Batch processing results:\", results)\n```\n\n### Visualization\n\nTo visualize the sentiment distribution of a text:\n\n```python\nfrom sentimentpredictor import plot_sentiment_distribution\n\nresult = predictor.predict(\"I am very happy today!\")\nplot_sentiment_distribution(result['probabilities'], predictor.labels.values())\n```\n\n### CLI Usage\n\nYou can also use the package from the command line:\n\n```bash\nsentimentpredictor --model roberta --text \"I am very happy today!\"\n```\n\n### DataFrame Integration\n\nIntegrate with pandas DataFrames to classify text columns:\n\n```python\nimport pandas as pd\nfrom sentimentpredictor import DataFrameSentimentPredictor\n\ndf = pd.DataFrame({\n 'text': [\"I am very happy today!\", \"I am so sad.\"]\n})\n\npredictor = DataFrameSentimentPredictor()\ndf = predictor.classify_dataframe(df, 'text')\nprint(df)\n```\n\n### Sentiment Trends Over Time\n\nAnalyze and plot sentiment trends over time:\n\n```python\nfrom sentimentpredictor import SentimentAnalysisTrends\n\ntexts = [\"I am very happy today!\", \"I am feeling okay.\", \"I am very sad.\"]\ntrends = SentimentAnalysisTrends()\nsentiments = trends.analyze_trends(texts)\ntrends.plot_trends(sentiments)\n```\n\n### Fine-tuning\n\nFine-tune a pre-trained model on your own dataset:\n\n```python\nfrom sentimentpredictor.fine_tune import fine_tune_model\n\n# Define your train and validation datasets\ntrain_dataset = ...\nval_dataset = ...\n\n# Fine-tune the model\nfine_tune_model(predictor.model, predictor.tokenizer, train_dataset, val_dataset, output_dir='fine_tuned_model')\n```\n\n### Logging Configuration\n\nBy default, the `sentimentpredictor` package logs messages at the `WARNING` level and above. If you need more detailed logging (e.g., for debugging), you can set the logging level to `INFO` or `DEBUG`:\n\n```python\nfrom sentimentpredictor.logger import set_logging_level\n\n# Set logging level to INFO\nset_logging_level('INFO')\n\n# Set logging level to DEBUG\nset_logging_level('DEBUG')\n```\n\nYou can set the logging level to one of the following: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`.\n\n### Running Tests\n\nRun the tests using pytest:\n\n```bash\npoetry run pytest\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgements\n\nThis package uses pre-trained models from the [Hugging Face Transformers library](https://github.com/huggingface/transformers).\n\n\n## Contributing\n\nContributions are welcome! Please see the [CONTRIBUTING](CONTRIBUTING.md) file for guidelines on how to contribute to this project.\n\n\n## Links\n\n- [Documentation](https://github.com/ankit-aglawe/sentimentpredictor#readme)\n- [PyPI](https://pypi.org/project/sentimentpredictor/)\n- [Source Code](https://github.com/ankit-aglawe/sentimentpredictor)\n- [Issue Tracker](https://github.com/ankit-aglawe/sentimentpredictor/issues)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A flexible sentiment analysis predictor package supporting multiple pre-trained models, customizable preprocessing, visualization tools, fine-tuning capabilities, and seamless integration with pandas DataFrames.",
"version": "0.1.3",
"project_urls": {
"Changelog": "https://github.com/ankit-aglawe/sentimentpredictor/releases",
"Documentation": "https://github.com/ankit-aglawe/sentimentpredictor#readme",
"Homepage": "https://github.com/ankit-aglawe/sentimentpredictor",
"Repository": "https://github.com/ankit-aglawe/sentimentpredictor",
"Source": "https://github.com/ankit-aglawe/sentimentpredictor",
"Tracker": "https://github.com/ankit-aglawe/sentimentpredictor/issues"
},
"split_keywords": [
"sentiment analysis",
" text analysis",
" machine learning",
" nlp",
" transformers",
" data science",
" pre-trained models",
" text mining"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8b57388bc8447437399217e19258856e98a82504be7f7b46aede64e6e26b8c5c",
"md5": "22affcf53ecd5e2378cf338348a8c2d0",
"sha256": "a0adf14cd8b7b523c1193055c6def2509f5afdb69f7858930826a0a555efec32"
},
"downloads": -1,
"filename": "sentimentpredictor-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "22affcf53ecd5e2378cf338348a8c2d0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 12475,
"upload_time": "2024-07-04T23:08:43",
"upload_time_iso_8601": "2024-07-04T23:08:43.864723Z",
"url": "https://files.pythonhosted.org/packages/8b/57/388bc8447437399217e19258856e98a82504be7f7b46aede64e6e26b8c5c/sentimentpredictor-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "da9a56da7fc17dc06786cdbff5510e1c5331ee6ec6a8ce247eeb038b96adf9e6",
"md5": "d675b304047316c6f368000445137055",
"sha256": "cdb10d73034d3eefd763a9d6dafadac42277ec131403e7943b510f10fd6b903e"
},
"downloads": -1,
"filename": "sentimentpredictor-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "d675b304047316c6f368000445137055",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 9724,
"upload_time": "2024-07-04T23:08:45",
"upload_time_iso_8601": "2024-07-04T23:08:45.452751Z",
"url": "https://files.pythonhosted.org/packages/da/9a/56da7fc17dc06786cdbff5510e1c5331ee6ec6a8ce247eeb038b96adf9e6/sentimentpredictor-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-04 23:08:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ankit-aglawe",
"github_project": "sentimentpredictor",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "sentimentpredictor"
}