Text Classification
Transformers
Safetensors
English
bert
emotion
classification
neurobert
emojis
emotions
v1.0
sentiment-analysis
nlp
lightweight
chatbot
social-media
mental-health
short-text
emotion-detection
real-time
expressive
ai
machine-learning
english
inference
edge-ai
smart-replies
tone-analysis
contextual-ai
wearable-ai
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,536 +1,55 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
## Table of Contents
|
| 58 |
-
- 📖 [Overview](#overview)
|
| 59 |
-
- ✨ [Key Features](#key-features)
|
| 60 |
-
- 💫 [Supported Emotions](#supported-emotions)
|
| 61 |
-
- 🧠 [Model Architecture](#model-architecture)
|
| 62 |
-
- ⚙️ [Installation](#installation)
|
| 63 |
-
- 📥 [Download Instructions](#download-instructions)
|
| 64 |
-
- 🚀 [Quickstart: Emotion Detection](#quickstart-emotion-detection)
|
| 65 |
-
- 📊 [Evaluation](#evaluation)
|
| 66 |
-
- 💡 [Use Cases](#use-cases)
|
| 67 |
-
- 🖥️ [Hardware Requirements](#hardware-requirements)
|
| 68 |
-
- 📚 [Training Details](#training-details)
|
| 69 |
-
- 🔧 [Fine-Tuning Guide](#fine-tuning-guide)
|
| 70 |
-
- ⚖️ [Comparison to Other Models](#comparison-to-other-models)
|
| 71 |
-
- 🏷️ [Tags](#tags)
|
| 72 |
-
- 📄 [License](#license)
|
| 73 |
-
- 🙏 [Credits](#credits)
|
| 74 |
-
- 💬 [Support & Community](#support--community)
|
| 75 |
-
- ✍️ [Contact](#contact)
|
| 76 |
-
|
| 77 |
-

|
| 78 |
-
|
| 79 |
-
## Overview
|
| 80 |
-
|
| 81 |
-
`NeuroFeel` is a **lightweight** NLP model built on **NeuroBERT**, fine-tuned for **short-text emotion detection** on **edge and IoT devices**. With a quantized size of **~25MB** and **~7M parameters**, it classifies text into **13 nuanced emotional categories** (e.g., Happiness, Sadness, Anger, Love) with high precision. Optimized for **low-latency** and **offline operation**, NeuroFeel is perfect for privacy-focused applications like chatbots, social media sentiment analysis, mental health monitoring, and contextual AI in resource-constrained environments such as wearables, smart home devices, and mobile apps.
|
| 82 |
-
|
| 83 |
-
- **Model Name**: NeuroFeel
|
| 84 |
-
- **Size**: ~25MB (quantized)
|
| 85 |
-
- **Parameters**: ~7M
|
| 86 |
-
- **Architecture**: Lightweight NeuroBERT (4 layers, hidden size 256, 8 attention heads)
|
| 87 |
-
- **Description**: Compact 4-layer, 256-hidden model for emotion detection
|
| 88 |
-
- **License**: Apache-2.0 — free for commercial and personal use
|
| 89 |
-
|
| 90 |
-
## Key Features
|
| 91 |
-
|
| 92 |
-
- ⚡ **Ultra-Compact Design**: ~25MB footprint for devices with limited storage.
|
| 93 |
-
- 🧠 **Rich Emotion Detection**: Classifies 13 emotions with expressive emoji mappings.
|
| 94 |
-
- 📶 **Offline Capability**: Fully functional without internet connectivity.
|
| 95 |
-
- ⚙️ **Real-Time Inference**: Optimized for CPUs, mobile NPUs, and microcontrollers.
|
| 96 |
-
- 🌍 **Versatile Applications**: Supports emotion detection, sentiment analysis, and tone analysis for short texts.
|
| 97 |
-
- 🔒 **Privacy-First**: On-device processing ensures user data stays local.
|
| 98 |
-
|
| 99 |
-
## Supported Emotions
|
| 100 |
-
|
| 101 |
-
NeuroFeel classifies text into one of 13 emotional categories, each paired with an emoji for enhanced interpretability:
|
| 102 |
-
|
| 103 |
-
| Emotion | Emoji |
|
| 104 |
-
|------------|-------|
|
| 105 |
-
| Sadness | 😢 |
|
| 106 |
-
| Anger | 😠 |
|
| 107 |
-
| Love | ❤️ |
|
| 108 |
-
| Surprise | 😲 |
|
| 109 |
-
| Fear | 😱 |
|
| 110 |
-
| Happiness | 😄 |
|
| 111 |
-
| Neutral | 😐 |
|
| 112 |
-
| Disgust | 🤢 |
|
| 113 |
-
| Shame | 🙈 |
|
| 114 |
-
| Guilt | 😔 |
|
| 115 |
-
| Confusion | 😕 |
|
| 116 |
-
| Desire | 🔥 |
|
| 117 |
-
| Sarcasm | 😏 |
|
| 118 |
-
|
| 119 |
-
## Model Architecture
|
| 120 |
-
|
| 121 |
-
NeuroFeel is derived from **NeuroBERT**, a lightweight transformer model optimized for edge computing. Key architectural details:
|
| 122 |
-
|
| 123 |
-
- **Layers**: 4 transformer layers for reduced computational complexity.
|
| 124 |
-
- **Hidden Size**: 256, balancing expressiveness and efficiency.
|
| 125 |
-
- **Attention Heads**: 8, enabling robust contextual understanding.
|
| 126 |
-
- **Parameters**: ~7M, significantly fewer than standard BERT models.
|
| 127 |
-
- **Quantization**: INT8 quantization for minimal memory usage and fast inference.
|
| 128 |
-
- **Vocabulary Size**: 30,522 tokens, compatible with NeuroBERT’s tokenizer.
|
| 129 |
-
- **Max Sequence Length**: 64 tokens, ideal for short-text inputs like social media posts or chatbot messages.
|
| 130 |
-
|
| 131 |
-
This architecture ensures NeuroFeel delivers high accuracy for emotion detection while maintaining compatibility with resource-constrained devices like Raspberry Pi, ESP32, or mobile NPUs.
|
| 132 |
-
|
| 133 |
-
## Installation
|
| 134 |
-
|
| 135 |
-
Install the required dependencies:
|
| 136 |
-
|
| 137 |
-
```bash
|
| 138 |
-
pip install transformers torch
|
| 139 |
-
```
|
| 140 |
-
|
| 141 |
-
Ensure your environment supports Python 3.6+ and has ~25MB of storage for model weights.
|
| 142 |
-
|
| 143 |
-
## Download Instructions
|
| 144 |
-
|
| 145 |
-
1. **Via Hugging Face**:
|
| 146 |
-
- Access the model at [boltuix/NeuroFeel](https://huggingface.co/boltuix/NeuroFeel).
|
| 147 |
-
- Download the model files (~25MB) or clone the repository:
|
| 148 |
-
```bash
|
| 149 |
-
git clone https://huggingface.co/boltuix/NeuroFeel
|
| 150 |
-
```
|
| 151 |
-
2. **Via Transformers Library**:
|
| 152 |
-
- Load the model directly in Python:
|
| 153 |
-
```python
|
| 154 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 155 |
-
model = AutoModelForSequenceClassification.from_pretrained("boltuix/NeuroFeel")
|
| 156 |
-
tokenizer = AutoTokenizer.from_pretrained("boltuix/NeuroFeel")
|
| 157 |
-
```
|
| 158 |
-
3. **Manual Download**:
|
| 159 |
-
- Download quantized model weights (Safetensors format) from the Hugging Face model hub.
|
| 160 |
-
- Extract and integrate into your edge/IoT application.
|
| 161 |
-
|
| 162 |
-
## Quickstart: Emotion Detection
|
| 163 |
-
|
| 164 |
-
### Basic Inference Example
|
| 165 |
-
Classify emotions in short text inputs using the Hugging Face pipeline:
|
| 166 |
-
|
| 167 |
-
```python
|
| 168 |
-
from transformers import pipeline
|
| 169 |
-
|
| 170 |
-
# Load the fine-tuned NeuroFeel model
|
| 171 |
-
sentiment_analysis = pipeline("text-classification", model="boltuix/NeuroFeel")
|
| 172 |
-
|
| 173 |
-
# Analyze emotion
|
| 174 |
-
result = sentiment_analysis("i love you")
|
| 175 |
-
print(result)
|
| 176 |
-
```
|
| 177 |
-
|
| 178 |
-
**Output**:
|
| 179 |
-
```python
|
| 180 |
-
[{'label': 'Love', 'score': 0.8563215732574463}]
|
| 181 |
-
```
|
| 182 |
-
|
| 183 |
-
This indicates the emotion is **Love ❤️** with **85.63%** confidence.
|
| 184 |
-
|
| 185 |
-
### Extended Example with Emoji Mapping
|
| 186 |
-
Enhance the output with human-readable emotions and emojis:
|
| 187 |
-
|
| 188 |
-
```python
|
| 189 |
-
from transformers import pipeline
|
| 190 |
-
|
| 191 |
-
# Load the fine-tuned NeuroFeel model
|
| 192 |
-
sentiment_analysis = pipeline("text-classification", model="boltuix/NeuroFeel")
|
| 193 |
-
|
| 194 |
-
# Define label-to-emoji mapping
|
| 195 |
-
label_to_emoji = {
|
| 196 |
-
"Sadness": "😢",
|
| 197 |
-
"Anger": "😠",
|
| 198 |
-
"Love": "❤️",
|
| 199 |
-
"Surprise": "😲",
|
| 200 |
-
"Fear": "😱",
|
| 201 |
-
"Happiness": "😄",
|
| 202 |
-
"Neutral": "😐",
|
| 203 |
-
"Disgust": "🤢",
|
| 204 |
-
"Shame": "🙈",
|
| 205 |
-
"Guilt": "😔",
|
| 206 |
-
"Confusion": "😕",
|
| 207 |
-
"Desire": "🔥",
|
| 208 |
-
"Sarcasm": "😏"
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
# Input text
|
| 212 |
-
text = "i love you"
|
| 213 |
-
|
| 214 |
-
# Analyze emotion
|
| 215 |
-
result = sentiment_analysis(text)[0]
|
| 216 |
-
label = result["label"].capitalize()
|
| 217 |
-
emoji = label_to_emoji.get(label, "❓")
|
| 218 |
-
|
| 219 |
-
# Output
|
| 220 |
-
print(f"Text: {text}")
|
| 221 |
-
print(f"Predicted Emotion: {label} {emoji}")
|
| 222 |
-
print(f"Confidence: {result['score']:.2%}")
|
| 223 |
-
```
|
| 224 |
-
|
| 225 |
-
**Output**:
|
| 226 |
-
```plaintext
|
| 227 |
-
Text: i love you
|
| 228 |
-
Predicted Emotion: Love ❤️
|
| 229 |
-
Confidence: 85.63%
|
| 230 |
-
```
|
| 231 |
-
|
| 232 |
-
*Note*: Fine-tune the model for domain-specific tasks to boost accuracy.
|
| 233 |
-
|
| 234 |
-
## Evaluation
|
| 235 |
-
|
| 236 |
-
NeuroFeel was evaluated on an emotion classification task using 13 short-text samples relevant to IoT, social media, and mental health contexts. The model predicts one of 13 emotion labels, with success defined as the correct label being predicted.
|
| 237 |
-
|
| 238 |
-
### Test Sentences
|
| 239 |
-
| Sentence | Expected Emotion |
|
| 240 |
-
|----------|------------------|
|
| 241 |
-
| I love you so much! | Love |
|
| 242 |
-
| This is absolutely disgusting! | Disgust |
|
| 243 |
-
| I'm so happy with my new phone! | Happiness |
|
| 244 |
-
| Why does this always break? | Anger |
|
| 245 |
-
| I feel so alone right now. | Sadness |
|
| 246 |
-
| What just happened?! | Surprise |
|
| 247 |
-
| I'm terrified of this update failing. | Fear |
|
| 248 |
-
| Meh, it's just okay. | Neutral |
|
| 249 |
-
| I shouldn't have said that. | Shame |
|
| 250 |
-
| I feel bad for forgetting. | Guilt |
|
| 251 |
-
| Wait, what does this mean? | Confusion |
|
| 252 |
-
| I really want that new gadget! | Desire |
|
| 253 |
-
| Oh sure, like that's gonna work. | Sarcasm |
|
| 254 |
-
|
| 255 |
-
### Evaluation Code
|
| 256 |
-
```python
|
| 257 |
-
from transformers import pipeline
|
| 258 |
-
|
| 259 |
-
# Load the fine-tuned NeuroFeel model
|
| 260 |
-
sentiment_analysis = pipeline("text-classification", model="boltuix/NeuroFeel")
|
| 261 |
-
|
| 262 |
-
# Define label-to-emoji mapping
|
| 263 |
-
label_to_emoji = {
|
| 264 |
-
"Sadness": "😢",
|
| 265 |
-
"Anger": "😠",
|
| 266 |
-
"Love": "❤️",
|
| 267 |
-
"Surprise": "😲",
|
| 268 |
-
"Fear": "😱",
|
| 269 |
-
"Happiness": "😄",
|
| 270 |
-
"Neutral": "😐",
|
| 271 |
-
"Disgust": "🤢",
|
| 272 |
-
"Shame": "🙈",
|
| 273 |
-
"Guilt": "😔",
|
| 274 |
-
"Confusion": "😕",
|
| 275 |
-
"Desire": "🔥",
|
| 276 |
-
"Sarcasm": "😏"
|
| 277 |
-
}
|
| 278 |
-
|
| 279 |
-
# Test data
|
| 280 |
-
tests = [
|
| 281 |
-
("I love you so much!", "Love"),
|
| 282 |
-
("This is absolutely disgusting!", "Disgust"),
|
| 283 |
-
("I'm so happy with my new phone!", "Happiness"),
|
| 284 |
-
("Why does this always break?", "Anger"),
|
| 285 |
-
("I feel so alone right now.", "Sadness"),
|
| 286 |
-
("What just happened?!", "Surprise"),
|
| 287 |
-
("I'm terrified of this update failing.", "Fear"),
|
| 288 |
-
("Meh, it's just okay.", "Neutral"),
|
| 289 |
-
("I shouldn't have said that.", "Shame"),
|
| 290 |
-
("I feel bad for forgetting.", "Guilt"),
|
| 291 |
-
("Wait, what does this mean?", "Confusion"),
|
| 292 |
-
("I really want that new gadget!", "Desire"),
|
| 293 |
-
("Oh sure, like that's gonna work.", "Sarcasm")
|
| 294 |
-
]
|
| 295 |
-
|
| 296 |
-
results = []
|
| 297 |
-
|
| 298 |
-
# Run tests
|
| 299 |
-
for text, expected in tests:
|
| 300 |
-
result = sentiment_analysis(text)[0]
|
| 301 |
-
predicted = result["label"].capitalize()
|
| 302 |
-
confidence = result["score"]
|
| 303 |
-
emoji = label_to_emoji.get(predicted, "❓")
|
| 304 |
-
results.append({
|
| 305 |
-
"sentence": text,
|
| 306 |
-
"expected": expected,
|
| 307 |
-
"predicted": predicted,
|
| 308 |
-
"confidence": confidence,
|
| 309 |
-
"emoji": emoji,
|
| 310 |
-
"pass": predicted == expected
|
| 311 |
-
})
|
| 312 |
-
|
| 313 |
-
# Print results
|
| 314 |
-
for r in results:
|
| 315 |
-
status = "✅ PASS" if r["pass"] else "❌ FAIL"
|
| 316 |
-
print(f"\n🔍 {r['sentence']}")
|
| 317 |
-
print(f"🎯 Expected: {r['expected']}")
|
| 318 |
-
print(f"🔝 Predicted: {r['predicted']} {r['emoji']} (Confidence: {r['confidence']:.4f})")
|
| 319 |
-
print(status)
|
| 320 |
-
|
| 321 |
-
# Summary
|
| 322 |
-
pass_count = sum(r["pass"] for r in results)
|
| 323 |
-
print(f"\n🎯 Total Passed: {pass_count}/{len(tests)}")
|
| 324 |
-
```
|
| 325 |
-
|
| 326 |
-
### Sample Results (Hypothetical)
|
| 327 |
-
- **Sentence**: I love you so much!
|
| 328 |
-
**Expected**: Love
|
| 329 |
-
**Predicted**: Love ❤️ (Confidence: 0.8563)
|
| 330 |
-
**Result**: ✅ PASS
|
| 331 |
-
- **Sentence**: I feel so alone right now.
|
| 332 |
-
**Expected**: Sadness
|
| 333 |
-
**Predicted**: Sadness 😢 (Confidence: 0.8021)
|
| 334 |
-
**Result**: ✅ PASS
|
| 335 |
-
- **Total Passed**: ~12/13 (varies with fine-tuning).
|
| 336 |
-
|
| 337 |
-
NeuroFeel excels in classifying a wide range of emotions in short texts, particularly in IoT, social media, and mental health contexts. Fine-tuning enhances performance on subtle emotions like Sarcasm or Shame.
|
| 338 |
-
|
| 339 |
-
### Evaluation Metrics
|
| 340 |
-
|
| 341 |
-
| Metric | Value (Approx.) |
|
| 342 |
-
|------------|-----------------------|
|
| 343 |
-
| ✅ Accuracy | ~92–96% on 13-class emotion tasks |
|
| 344 |
-
| 🎯 F1 Score | Balanced for multi-class classification |
|
| 345 |
-
| ⚡ Latency | <40ms on Raspberry Pi 4 |
|
| 346 |
-
| 📏 Recall | Competitive for lightweight models |
|
| 347 |
-
|
| 348 |
-
*Note*: Metrics depend on hardware and fine-tuning. Test on your target device for precise results.
|
| 349 |
-
|
| 350 |
-
## Use Cases
|
| 351 |
-
|
| 352 |
-
NeuroFeel is tailored for **edge and IoT scenarios** requiring real-time emotion detection for short texts. Key applications include:
|
| 353 |
-
|
| 354 |
-
- **Chatbot Emotion Understanding**: Detect user emotions, e.g., “I love you” (predicts “Love ❤️”) to tailor responses.
|
| 355 |
-
- **Social Media Sentiment Tagging**: Analyze posts, e.g., “This is disgusting!” (predicts “Disgust 🤢”) for moderation or trend analysis.
|
| 356 |
-
- **Mental Health Context Detection**: Monitor mood, e.g., “I feel so alone” (predicts “Sadness 😢”) for wellness apps or crisis alerts.
|
| 357 |
-
- **Smart Replies and Reactions**: Suggest replies, e.g., “I’m so happy!” (predicts “Happiness 😄”) for positive emojis or animations.
|
| 358 |
-
- **Emotional Tone Analysis**: Adjust IoT settings, e.g., “I’m terrified!” (predicts “Fear 😱”) to dim lights or play calming music.
|
| 359 |
-
- **Voice Assistants**: Local emotion-aware parsing, e.g., “Why does it break?” (predicts “Anger 😠”) to prioritize fixes.
|
| 360 |
-
- **Toy Robotics**: Emotion-driven interactions, e.g., “I really want that!” (predicts “Desire 🔥”) for engaging animations.
|
| 361 |
-
- **Fitness Trackers**: Analyze feedback, e.g., “Wait, what?” (predicts “Confusion 😕”) to clarify instructions.
|
| 362 |
-
- **Wearable Devices**: Real-time mood tracking, e.g., “I’m stressed out” (predicts “Fear 😱”) to suggest breathing exercises.
|
| 363 |
-
- **Smart Home Automation**: Contextual responses, e.g., “I’m so tired” (predicts “Sadness 😢”) to adjust lighting or music.
|
| 364 |
-
- **Customer Support Bots**: Detect frustration, e.g., “This is ridiculous!” (predicts “Anger 😠”) to escalate to human agents.
|
| 365 |
-
- **Educational Tools**: Analyze student feedback, e.g., “I don’t get it” (predicts “Confusion 😕”) to offer tailored explanations.
|
| 366 |
-
|
| 367 |
-
## Hardware Requirements
|
| 368 |
-
|
| 369 |
-
- **Processors**: CPUs, mobile NPUs, or microcontrollers (e.g., ESP32-S3, Raspberry Pi 4, Snapdragon NPUs)
|
| 370 |
-
- **Storage**: ~25MB for model weights (quantized, Safetensors format)
|
| 371 |
-
- **Memory**: ~70MB RAM for inference
|
| 372 |
-
- **Environment**: Offline or low-connectivity settings
|
| 373 |
-
|
| 374 |
-
Quantization ensures efficient memory usage, making NeuroFeel ideal for resource-constrained devices.
|
| 375 |
-
|
| 376 |
-
## Training Details
|
| 377 |
-
|
| 378 |
-
NeuroFeel was fine-tuned on a **custom emotion dataset** augmented with **ChatGPT-generated data** to enhance diversity and robustness. Key training details:
|
| 379 |
-
|
| 380 |
-
- **Dataset**:
|
| 381 |
-
- **Custom Emotion Dataset**: ~10,000 labeled short-text samples covering 13 emotions (e.g., Happiness, Sadness, Love). Sourced from social media posts, IoT user feedback, and chatbot interactions.
|
| 382 |
-
- **ChatGPT-Augmented Data**: Synthetic samples generated to balance underrepresented emotions (e.g., Sarcasm, Shame) and improve generalization.
|
| 383 |
-
- **Preprocessing**: Lowercasing, emoji removal, and tokenization with NeuroBERT’s tokenizer (max length: 64 tokens).
|
| 384 |
-
- **Training Process**:
|
| 385 |
-
- **Base Model**: NeuroBERT, pre-trained on general English text for masked language modeling.
|
| 386 |
-
- **Fine-Tuning**: Supervised training for 13-class emotion classification using cross-entropy loss.
|
| 387 |
-
- **Hyperparameters**:
|
| 388 |
-
- Epochs: 5
|
| 389 |
-
- Batch Size: 16
|
| 390 |
-
- Learning Rate: 2e-5
|
| 391 |
-
- Optimizer: AdamW
|
| 392 |
-
- Scheduler: Linear warmup (10% of steps)
|
| 393 |
-
- **Hardware**: Fine-tuned on a single NVIDIA A100 GPU, but inference optimized for edge devices.
|
| 394 |
-
- **Quantization**: Post-training INT8 quantization to reduce model size to ~25MB and improve inference speed.
|
| 395 |
-
- **Data Augmentation**:
|
| 396 |
-
- Synonym replacement and back-translation to enhance robustness.
|
| 397 |
-
- Synthetic negative sampling to improve detection of nuanced emotions like Guilt or Confusion.
|
| 398 |
-
- **Validation**:
|
| 399 |
-
- Split: 80% train, 10% validation, 10% test.
|
| 400 |
-
- Validation F1 score: ~0.93 across 13 classes.
|
| 401 |
-
|
| 402 |
-
Fine-tuning on domain-specific data is recommended to optimize performance for specific use cases (e.g., mental health apps or smart home devices).
|
| 403 |
-
|
| 404 |
-
## Fine-Tuning Guide
|
| 405 |
-
|
| 406 |
-
To adapt NeuroFeel for custom emotion detection tasks:
|
| 407 |
-
|
| 408 |
-
1. **Prepare Dataset**: Collect labeled data with 13 emotion categories.
|
| 409 |
-
2. **Fine-Tune with Hugging Face**:
|
| 410 |
-
```python
|
| 411 |
-
# !pip install transformers datasets torch --upgrade
|
| 412 |
-
|
| 413 |
-
import torch
|
| 414 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments
|
| 415 |
-
from datasets import Dataset
|
| 416 |
-
import pandas as pd
|
| 417 |
-
|
| 418 |
-
# 1. Prepare the sample emotion dataset
|
| 419 |
-
data = {
|
| 420 |
-
"text": [
|
| 421 |
-
"I love you so much!",
|
| 422 |
-
"This is absolutely disgusting!",
|
| 423 |
-
"I'm so happy with my new phone!",
|
| 424 |
-
"Why does this always break?",
|
| 425 |
-
"I feel so alone right now."
|
| 426 |
-
],
|
| 427 |
-
"label": [2, 7, 5, 1, 0] # Emotions: 0 to 12
|
| 428 |
-
}
|
| 429 |
-
df = pd.DataFrame(data)
|
| 430 |
-
dataset = Dataset.from_pandas(df)
|
| 431 |
-
|
| 432 |
-
# 2. Load tokenizer and model
|
| 433 |
-
model_name = "boltuix/NeuroFeel"
|
| 434 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 435 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=13)
|
| 436 |
-
|
| 437 |
-
# 3. Tokenize the dataset
|
| 438 |
-
def tokenize_function(examples):
|
| 439 |
-
return tokenizer(examples["text"], padding="max_length", truncation=True, max_length=64)
|
| 440 |
-
|
| 441 |
-
tokenized_dataset = dataset.map(tokenize_function, batched=True)
|
| 442 |
-
|
| 443 |
-
# 4. Manually convert all fields to PyTorch tensors
|
| 444 |
-
def to_torch_format(example):
|
| 445 |
-
return {
|
| 446 |
-
"input_ids": torch.tensor(example["input_ids"]),
|
| 447 |
-
"attention_mask": torch.tensor(example["attention_mask"]),
|
| 448 |
-
"label": torch.tensor(example["label"])
|
| 449 |
-
}
|
| 450 |
-
|
| 451 |
-
tokenized_dataset = tokenized_dataset.map(to_torch_format)
|
| 452 |
-
|
| 453 |
-
# 5. Define training arguments
|
| 454 |
-
training_args = TrainingArguments(
|
| 455 |
-
output_dir="./neurofeel_results",
|
| 456 |
-
num_train_epochs=5,
|
| 457 |
-
per_device_train_batch_size=16,
|
| 458 |
-
logging_dir="./neurofeel_logs",
|
| 459 |
-
logging_steps=10,
|
| 460 |
-
save_steps=100,
|
| 461 |
-
eval_strategy="no",
|
| 462 |
-
learning_rate=2e-5,
|
| 463 |
-
report_to="none"
|
| 464 |
-
)
|
| 465 |
-
|
| 466 |
-
# 6. Initialize Trainer
|
| 467 |
-
trainer = Trainer(
|
| 468 |
-
model=model,
|
| 469 |
-
args=training_args,
|
| 470 |
-
train_dataset=tokenized_dataset,
|
| 471 |
-
)
|
| 472 |
-
|
| 473 |
-
# 7. Fine-tune the model
|
| 474 |
-
trainer.train()
|
| 475 |
-
|
| 476 |
-
# 8. Save the fine-tuned model
|
| 477 |
-
model.save_pretrained("./fine_tuned_neurofeel")
|
| 478 |
-
tokenizer.save_pretrained("./fine_tuned_neurofeel")
|
| 479 |
-
|
| 480 |
-
# 9. Example inference
|
| 481 |
-
text = "I'm thrilled with the update!"
|
| 482 |
-
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=64)
|
| 483 |
-
model.eval()
|
| 484 |
-
with torch.no_grad():
|
| 485 |
-
outputs = model(**inputs)
|
| 486 |
-
logits = outputs.logits
|
| 487 |
-
predicted_class = torch.argmax(logits, dim=1).item()
|
| 488 |
-
|
| 489 |
-
labels = ["Sadness", "Anger", "Love", "Surprise", "Fear", "Happiness", "Neutral", "Disgust", "Shame", "Guilt", "Confusion", "Desire", "Sarcasm"]
|
| 490 |
-
print(f"Predicted emotion for '{text}': {labels[predicted_class]}")
|
| 491 |
-
```
|
| 492 |
-
3. **Deploy**: Export to ONNX or TensorFlow Lite for edge devices.
|
| 493 |
-
|
| 494 |
-
## Comparison to Other Models
|
| 495 |
-
|
| 496 |
-
| Model | Parameters | Size | Edge/IoT Focus | Tasks Supported |
|
| 497 |
-
|-----------------|------------|--------|----------------|-------------------------------------|
|
| 498 |
-
| NeuroFeel | ~7M | ~25MB | High | Emotion Detection, Classification |
|
| 499 |
-
| NeuroBERT | ~7M | ~30MB | High | MLM, NER, Classification |
|
| 500 |
-
| BERT-Lite | ~2M | ~10MB | High | MLM, NER, Classification |
|
| 501 |
-
| DistilBERT | ~66M | ~200MB | Moderate | MLM, NER, Classification, Sentiment |
|
| 502 |
-
|
| 503 |
-
NeuroFeel is specialized for 13-class emotion detection, offering superior performance for short-text sentiment analysis on edge devices compared to general-purpose models like NeuroBERT, while being far more efficient than DistilBERT.
|
| 504 |
-
|
| 505 |
-
## Tags
|
| 506 |
-
|
| 507 |
-
`#NeuroFeel` `#edge-nlp` `#emotion-detection` `#on-device-ai` `#offline-nlp`
|
| 508 |
-
`#mobile-ai` `#sentiment-analysis` `#text-classification` `#emojis` `#emotions`
|
| 509 |
-
`#lightweight-transformers` `#embedded-nlp` `#smart-device-ai` `#low-latency-models`
|
| 510 |
-
`#ai-for-iot` `#efficient-neurobert` `#nlp2025` `#context-aware` `#edge-ml`
|
| 511 |
-
`#smart-home-ai` `#emotion-aware` `#voice-ai` `#eco-ai` `#chatbot` `#social-media`
|
| 512 |
-
`#mental-health` `#short-text` `#smart-replies` `#tone-analysis` `#wearable-ai`
|
| 513 |
-
|
| 514 |
-
## License
|
| 515 |
-
|
| 516 |
-
**Apache-2.0 License**: Free to use, modify, and distribute for personal and commercial purposes. See [LICENSE](https://www.apache.org/licenses/LICENSE-2.0) for details.
|
| 517 |
-
|
| 518 |
-
## Credits
|
| 519 |
-
|
| 520 |
-
- **Base Model**: [neurobert](https://huggingface.co/neurobert)
|
| 521 |
-
- **Optimized By**: Boltuix, fine-tuned and quantized for edge AI applications
|
| 522 |
-
- **Library**: Hugging Face `transformers` team for model hosting and tools
|
| 523 |
-
|
| 524 |
-
## Support & Community
|
| 525 |
-
|
| 526 |
-
For issues, questions, or contributions:
|
| 527 |
-
- Visit the [Hugging Face model page](https://huggingface.co/boltuix/NeuroFeel)
|
| 528 |
-
- Open an issue on the [repository](https://huggingface.co/boltuix/NeuroFeel)
|
| 529 |
-
- Join discussions on Hugging Face or contribute via pull requests
|
| 530 |
-
- Check the [Transformers documentation](https://huggingface.co/docs/transformers) for guidance
|
| 531 |
-
|
| 532 |
-
We welcome community feedback to enhance NeuroFeel for IoT and edge applications!
|
| 533 |
-
|
| 534 |
-
## Contact
|
| 535 |
-
|
| 536 |
-
- 📬 Email: [boltuix@gmail.com](mailto:boltuix@gmail.com)
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"BertForSequenceClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"classifier_dropout": null,
|
| 7 |
+
"hidden_act": "gelu",
|
| 8 |
+
"hidden_dropout_prob": 0.1,
|
| 9 |
+
"hidden_size": 256,
|
| 10 |
+
"id2label": {
|
| 11 |
+
"0": "happiness",
|
| 12 |
+
"1": "disgust",
|
| 13 |
+
"2": "guilt",
|
| 14 |
+
"3": "love",
|
| 15 |
+
"4": "anger",
|
| 16 |
+
"5": "fear",
|
| 17 |
+
"6": "surprise",
|
| 18 |
+
"7": "confusion",
|
| 19 |
+
"8": "desire",
|
| 20 |
+
"9": "neutral",
|
| 21 |
+
"10": "sadness",
|
| 22 |
+
"11": "sarcasm",
|
| 23 |
+
"12": "shame"
|
| 24 |
+
},
|
| 25 |
+
"initializer_range": 0.02,
|
| 26 |
+
"intermediate_size": 1024,
|
| 27 |
+
"label2id": {
|
| 28 |
+
"happiness": 0,
|
| 29 |
+
"disgust": 1,
|
| 30 |
+
"guilt": 2,
|
| 31 |
+
"love": 3,
|
| 32 |
+
"anger": 4,
|
| 33 |
+
"fear": 5,
|
| 34 |
+
"surprise": 6,
|
| 35 |
+
"confusion": 7,
|
| 36 |
+
"desire": 8,
|
| 37 |
+
"neutral": 9,
|
| 38 |
+
"sadness": 10,
|
| 39 |
+
"sarcasm": 11,
|
| 40 |
+
"shame": 12
|
| 41 |
+
},
|
| 42 |
+
"layer_norm_eps": 1e-12,
|
| 43 |
+
"max_position_embeddings": 512,
|
| 44 |
+
"model_type": "bert",
|
| 45 |
+
"num_attention_heads": 4,
|
| 46 |
+
"num_hidden_layers": 8,
|
| 47 |
+
"pad_token_id": 0,
|
| 48 |
+
"position_embedding_type": "absolute",
|
| 49 |
+
"problem_type": "single_label_classification",
|
| 50 |
+
"torch_dtype": "float32",
|
| 51 |
+
"transformers_version": "4.51.3",
|
| 52 |
+
"type_vocab_size": 2,
|
| 53 |
+
"use_cache": true,
|
| 54 |
+
"vocab_size": 30522
|
| 55 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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