Update README.md
Browse files
README.md
CHANGED
|
@@ -29,30 +29,121 @@ Fast Emotion-X is a state-of-the-art emotion detection model fine-tuned from Mic
|
|
| 29 |
- **π Dataset:** [dair-ai/emotion](https://huggingface.co/dair-ai/emotion)
|
| 30 |
- **βοΈ Fine-tuning:** This model was fine-tuned for emotion detection with a classification head for six emotional categories (anger, disgust, fear, joy, sadness, surprise).
|
| 31 |
|
| 32 |
-
## ποΈ Training
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
-
- **π¦ Batch Size:** 4
|
| 38 |
-
- **βοΈ Weight Decay:** 0.01
|
| 39 |
-
- **π
Evaluation Strategy:** Epoch
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
- **π Eval Loss:** 0.0858
|
| 44 |
-
- **β±οΈ Eval Runtime:** 110070.6349 seconds
|
| 45 |
-
- **π Eval Samples/Second:** 78.495
|
| 46 |
-
- **π Eval Steps/Second:** 2.453
|
| 47 |
-
- **π Train Loss:** 0.1049
|
| 48 |
-
- **β³ Eval Accuracy:** 94.6%
|
| 49 |
-
- **π Eval Precision:** 94.8%
|
| 50 |
-
- **β±οΈ Eval Recall:** 94.5%
|
| 51 |
-
- **π Eval F1 Score:** 94.7%
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
```python
|
| 58 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
@@ -74,13 +165,27 @@ emotion = predict_emotion(text)
|
|
| 74 |
print("Detected Emotion:", emotion)
|
| 75 |
```
|
| 76 |
|
| 77 |
-
##
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
-
|
| 82 |
-
-
|
| 83 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
## π Model Card Data
|
|
|
|
| 29 |
- **π Dataset:** [dair-ai/emotion](https://huggingface.co/dair-ai/emotion)
|
| 30 |
- **βοΈ Fine-tuning:** This model was fine-tuned for emotion detection with a classification head for six emotional categories (anger, disgust, fear, joy, sadness, surprise).
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
+
## π Emotion Labels
|
| 34 |
+
- π Anger
|
| 35 |
+
- π€’ Disgust
|
| 36 |
+
- π¨ Fear
|
| 37 |
+
- π Joy
|
| 38 |
+
- π’ Sadness
|
| 39 |
+
- π² Surprise
|
| 40 |
+
-
|
| 41 |
|
| 42 |
+
## π Usage
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
You can use this model directly with python package or the Hugging Face `transformers` library:
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
### Installation
|
| 48 |
+
|
| 49 |
+
You can install the package using pip:
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
pip install emotionclassifier
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
### Basic Usage
|
| 56 |
+
|
| 57 |
+
Here's an example of how to use the `emotionclassifier` to classify a single text:
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
from emotionclassifier import EmotionClassifier
|
| 61 |
+
|
| 62 |
+
# Initialize the classifier with the default model
|
| 63 |
+
classifier = EmotionClassifier()
|
| 64 |
+
|
| 65 |
+
# Classify a single text
|
| 66 |
+
text = "I am very happy today!"
|
| 67 |
+
result = classifier.predict(text)
|
| 68 |
+
print("Emotion:", result['label'])
|
| 69 |
+
print("Confidence:", result['confidence'])
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
### Batch Processing
|
| 73 |
+
|
| 74 |
+
You can classify multiple texts at once using the `predict_batch` method:
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
texts = ["I am very happy today!", "I am so sad."]
|
| 78 |
+
results = classifier.predict_batch(texts)
|
| 79 |
+
print("Batch processing results:", results)
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
### Visualization
|
| 83 |
+
|
| 84 |
+
To visualize the emotion distribution of a text:
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
+
from emotionclassifier import plot_emotion_distribution
|
| 88 |
+
|
| 89 |
+
result = classifier.predict("I am very happy today!")
|
| 90 |
+
plot_emotion_distribution(result['probabilities'], classifier.labels.values())
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
### CLI Usage
|
| 94 |
+
|
| 95 |
+
You can also use the package from the command line:
|
| 96 |
+
|
| 97 |
+
```bash
|
| 98 |
+
emotionclassifier --model deberta-v3-small --text "I am very happy today!"
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
### DataFrame Integration
|
| 102 |
|
| 103 |
+
Integrate with pandas DataFrames to classify text columns:
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
import pandas as pd
|
| 107 |
+
from emotionclassifier import DataFrameEmotionClassifier
|
| 108 |
+
|
| 109 |
+
df = pd.DataFrame({
|
| 110 |
+
'text': ["I am very happy today!", "I am so sad."]
|
| 111 |
+
})
|
| 112 |
+
|
| 113 |
+
classifier = DataFrameEmotionClassifier()
|
| 114 |
+
df = classifier.classify_dataframe(df, 'text')
|
| 115 |
+
print(df)
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
### Emotion Trends Over Time
|
| 119 |
+
|
| 120 |
+
Analyze and plot emotion trends over time:
|
| 121 |
+
|
| 122 |
+
```python
|
| 123 |
+
from emotionclassifier import EmotionTrends
|
| 124 |
+
|
| 125 |
+
texts = ["I am very happy today!", "I am feeling okay.", "I am very sad."]
|
| 126 |
+
trends = EmotionTrends()
|
| 127 |
+
emotions = trends.analyze_trends(texts)
|
| 128 |
+
trends.plot_trends(emotions)
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
### Fine-tuning
|
| 132 |
+
|
| 133 |
+
Fine-tune a pre-trained model on your own dataset:
|
| 134 |
+
|
| 135 |
+
```python
|
| 136 |
+
from emotionclassifier.fine_tune import fine_tune_model
|
| 137 |
+
|
| 138 |
+
# Define your train and validation datasets
|
| 139 |
+
train_dataset = ...
|
| 140 |
+
val_dataset = ...
|
| 141 |
+
|
| 142 |
+
# Fine-tune the model
|
| 143 |
+
fine_tune_model(classifier.model, classifier.tokenizer, train_dataset, val_dataset, output_dir='fine_tuned_model')
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
### Using transformers
|
| 147 |
|
| 148 |
```python
|
| 149 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
|
|
| 165 |
print("Detected Emotion:", emotion)
|
| 166 |
```
|
| 167 |
|
| 168 |
+
## ποΈ Training
|
| 169 |
+
|
| 170 |
+
The model was trained using the following parameters:
|
| 171 |
+
|
| 172 |
+
- **π§ Learning Rate:** 2e-5
|
| 173 |
+
- **π¦ Batch Size:** 4
|
| 174 |
+
- **βοΈ Weight Decay:** 0.01
|
| 175 |
+
- **π
Evaluation Strategy:** Epoch
|
| 176 |
+
|
| 177 |
+
### ποΈ Training Details
|
| 178 |
+
|
| 179 |
+
- **π Eval Loss:** 0.0858
|
| 180 |
+
- **β±οΈ Eval Runtime:** 110070.6349 seconds
|
| 181 |
+
- **π Eval Samples/Second:** 78.495
|
| 182 |
+
- **π Eval Steps/Second:** 2.453
|
| 183 |
+
- **π Train Loss:** 0.1049
|
| 184 |
+
- **β³ Eval Accuracy:** 94.6%
|
| 185 |
+
- **π Eval Precision:** 94.8%
|
| 186 |
+
- **β±οΈ Eval Recall:** 94.5%
|
| 187 |
+
- **π Eval F1 Score:** 94.7%
|
| 188 |
+
|
| 189 |
|
| 190 |
|
| 191 |
## π Model Card Data
|