emotionclassifier


Nameemotionclassifier JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/ankit-aglawe/emotionclassifier
SummaryA flexible emotion classifier with support for multiple models
upload_time2024-07-04 15:26:26
maintainerNone
docs_urlNone
authorAnkit Aglawe
requires_python<4.0,>=3.9
licenseMIT
keywords emotion classification text emotion classification emotion prediction python emotion analysis nlp natural language processing machine learning deep learning transformers
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![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/emotionclassifier) [![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/emotionclassifier)](https://pepy.tech/project/emotionclassifier)

# Text Emotion Classifier

![Emotion Classifier Logo](https://raw.githubusercontent.com/ankit-aglawe/emotionclassifier/main/assets/EmotionClassifier-bg.jpeg)


A flexible emotion classifier package with support for multiple models, customizable preprocessing, visualization tools, fine-tuning capabilities, and more.

## Overview

`emotionclassifier` is a Python package designed to classify emotions in text using various pre-trained models from Hugging Face's Transformers library. This package provides a user-friendly interface for emotion 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 emotion distributions and trends over time.
- **Fine-tuning Capability**: Fine-tune models on your own datasets.
- **User-friendly CLI**: Command-line interface for quick emotion classification.
- **Integration with Data Platforms**: Seamless integration with pandas DataFrames.
- **Extended Post-processing**: Additional utilities for detailed emotion analysis.

## Emotion Labels
- 😠 Anger
- 🤢 Disgust
- 😨 Fear
- 😊 Joy
- 😢 Sadness
- 😲 Surprise


## Installation

You can install the package using pip:

```bash
pip install emotionclassifier
```

## Usage

### Basic Usage

Here's an example of how to use the `EmotionClassifier` to classify a single text:

```python
from emotionclassifier import EmotionClassifier

# Initialize the classifier with the default model
classifier = EmotionClassifier()

# Classify a single text
text = "I am very happy today!"
result = classifier.predict(text)
print("Emotion:", 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 = classifier.predict_batch(texts)
print("Batch processing results:", results)
```

### Visualization

To visualize the emotion distribution of a text:

```python
from emotionclassifier import plot_emotion_distribution

result = classifier.predict("I am very happy today!")
plot_emotion_distribution(result['probabilities'], classifier.labels.values())
```

### CLI Usage

You can also use the package from the command line:

```bash
emotionclassifier --model deberta-v3-small --text "I am very happy today!"
```

### DataFrame Integration

Integrate with pandas DataFrames to classify text columns:

```python
import pandas as pd
from emotionclassifier import DataFrameEmotionClassifier

df = pd.DataFrame({
    'text': ["I am very happy today!", "I am so sad."]
})

classifier = DataFrameEmotionClassifier()
df = classifier.classify_dataframe(df, 'text')
print(df)
```

### Emotion Trends Over Time

Analyze and plot emotion trends over time:

```python
from emotionclassifier import EmotionTrends

texts = ["I am very happy today!", "I am feeling okay.", "I am very sad."]
trends = EmotionTrends()
emotions = trends.analyze_trends(texts)
trends.plot_trends(emotions)
```

### Fine-tuning

Fine-tune a pre-trained model on your own dataset:

```python
from emotionclassifier.fine_tune import fine_tune_model

# Define your train and validation datasets
train_dataset = ...
val_dataset = ...

# Fine-tune the model
fine_tune_model(classifier.model, classifier.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`.


### 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/emotionclassifier#readme)
- [PyPI](https://pypi.org/project/emotionclassifier/)
- [Source Code](https://github.com/ankit-aglawe/emotionclassifier)
- [Issue Tracker](https://github.com/ankit-aglawe/emotionclassifier/issues)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ankit-aglawe/emotionclassifier",
    "name": "emotionclassifier",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "emotion classification, text emotion classification, emotion prediction python, emotion analysis, NLP, natural language processing, machine learning, deep learning, transformers",
    "author": "Ankit Aglawe",
    "author_email": "aglawe.ankit@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0f/ac/87847f2635fae2372894b35ffce013e0100a6fe6c2464b5442cdad67db12/emotionclassifier-0.1.4.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/emotionclassifier) [![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/emotionclassifier)](https://pepy.tech/project/emotionclassifier)\n\n# Text Emotion Classifier\n\n![Emotion Classifier Logo](https://raw.githubusercontent.com/ankit-aglawe/emotionclassifier/main/assets/EmotionClassifier-bg.jpeg)\n\n\nA flexible emotion classifier package with support for multiple models, customizable preprocessing, visualization tools, fine-tuning capabilities, and more.\n\n## Overview\n\n`emotionclassifier` is a Python package designed to classify emotions in text using various pre-trained models from Hugging Face's Transformers library. This package provides a user-friendly interface for emotion 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 emotion 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 emotion classification.\n- **Integration with Data Platforms**: Seamless integration with pandas DataFrames.\n- **Extended Post-processing**: Additional utilities for detailed emotion analysis.\n\n## Emotion Labels\n- \ud83d\ude20 Anger\n- \ud83e\udd22 Disgust\n- \ud83d\ude28 Fear\n- \ud83d\ude0a Joy\n- \ud83d\ude22 Sadness\n- \ud83d\ude32 Surprise\n\n\n## Installation\n\nYou can install the package using pip:\n\n```bash\npip install emotionclassifier\n```\n\n## Usage\n\n### Basic Usage\n\nHere's an example of how to use the `EmotionClassifier` to classify a single text:\n\n```python\nfrom emotionclassifier import EmotionClassifier\n\n# Initialize the classifier with the default model\nclassifier = EmotionClassifier()\n\n# Classify a single text\ntext = \"I am very happy today!\"\nresult = classifier.predict(text)\nprint(\"Emotion:\", 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 = classifier.predict_batch(texts)\nprint(\"Batch processing results:\", results)\n```\n\n### Visualization\n\nTo visualize the emotion distribution of a text:\n\n```python\nfrom emotionclassifier import plot_emotion_distribution\n\nresult = classifier.predict(\"I am very happy today!\")\nplot_emotion_distribution(result['probabilities'], classifier.labels.values())\n```\n\n### CLI Usage\n\nYou can also use the package from the command line:\n\n```bash\nemotionclassifier --model deberta-v3-small --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 emotionclassifier import DataFrameEmotionClassifier\n\ndf = pd.DataFrame({\n    'text': [\"I am very happy today!\", \"I am so sad.\"]\n})\n\nclassifier = DataFrameEmotionClassifier()\ndf = classifier.classify_dataframe(df, 'text')\nprint(df)\n```\n\n### Emotion Trends Over Time\n\nAnalyze and plot emotion trends over time:\n\n```python\nfrom emotionclassifier import EmotionTrends\n\ntexts = [\"I am very happy today!\", \"I am feeling okay.\", \"I am very sad.\"]\ntrends = EmotionTrends()\nemotions = trends.analyze_trends(texts)\ntrends.plot_trends(emotions)\n```\n\n### Fine-tuning\n\nFine-tune a pre-trained model on your own dataset:\n\n```python\nfrom emotionclassifier.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(classifier.model, classifier.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\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/emotionclassifier#readme)\n- [PyPI](https://pypi.org/project/emotionclassifier/)\n- [Source Code](https://github.com/ankit-aglawe/emotionclassifier)\n- [Issue Tracker](https://github.com/ankit-aglawe/emotionclassifier/issues)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A flexible emotion classifier with support for multiple models",
    "version": "0.1.4",
    "project_urls": {
        "Changelog": "https://github.com/ankit-aglawe/emotionclassifier/releases",
        "Documentation": "https://github.com/ankit-aglawe/emotionclassifier#readme",
        "Homepage": "https://github.com/ankit-aglawe/emotionclassifier",
        "Repository": "https://github.com/ankit-aglawe/emotionclassifier",
        "Source": "https://github.com/ankit-aglawe/emotionclassifier",
        "Tracker": "https://github.com/ankit-aglawe/emotionclassifier/issues"
    },
    "split_keywords": [
        "emotion classification",
        " text emotion classification",
        " emotion prediction python",
        " emotion analysis",
        " nlp",
        " natural language processing",
        " machine learning",
        " deep learning",
        " transformers"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8060e2e01ba6c92c16491aa05e35f6e821fe2b2c689fbae0d97d2618f48e438b",
                "md5": "cae442f460b5616ccd3b7d0e5d627b6e",
                "sha256": "c9a9337b33464513d9d2221e5f1aefc35264b85ee787f800cab709e8fa7b42a9"
            },
            "downloads": -1,
            "filename": "emotionclassifier-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cae442f460b5616ccd3b7d0e5d627b6e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 12178,
            "upload_time": "2024-07-04T15:26:24",
            "upload_time_iso_8601": "2024-07-04T15:26:24.934970Z",
            "url": "https://files.pythonhosted.org/packages/80/60/e2e01ba6c92c16491aa05e35f6e821fe2b2c689fbae0d97d2618f48e438b/emotionclassifier-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0fac87847f2635fae2372894b35ffce013e0100a6fe6c2464b5442cdad67db12",
                "md5": "b335a67dd14648f53600cf2ad182ef5f",
                "sha256": "6cae356781ac08ce91a12d5405f835714a3cb0942f667e7fbb107392f57769e8"
            },
            "downloads": -1,
            "filename": "emotionclassifier-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "b335a67dd14648f53600cf2ad182ef5f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 9797,
            "upload_time": "2024-07-04T15:26:26",
            "upload_time_iso_8601": "2024-07-04T15:26:26.541656Z",
            "url": "https://files.pythonhosted.org/packages/0f/ac/87847f2635fae2372894b35ffce013e0100a6fe6c2464b5442cdad67db12/emotionclassifier-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-04 15:26:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ankit-aglawe",
    "github_project": "emotionclassifier",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "emotionclassifier"
}
        
Elapsed time: 0.47944s