CoolFace
Modelpublic

boltuix/bert-emotion

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
68likes1.7kdownloads
Model Card

Banner

😊 BERT-Emotion β€” Lightweight BERT for Real-Time Emotion Detection 🌟

![License: Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) ![Model Size](#) ![Tasks](#) ![Inference Speed](#)

Table of Contents

Banner

Overview

BERT-Emotion is a lightweight NLP model derived from bert-mini and bert-micro, fine-tuned for short-text emotion detection on edge and IoT devices. With a quantized size of ~20MB and ~6M parameters, it classifies text into 13 rich emotional categories (e.g., Happiness, Sadness, Anger, Love) with high accuracy. Optimized for low-latency and offline operation, BERT-Emotion is ideal for privacy-first applications like chatbots, social media sentiment analysis, and mental health monitoring in resource-constrained environments such as mobile apps, wearables, and smart home devices.

  • β€”Model Name: BERT-Emotion
  • β€”Size: ~20MB (quantized)
  • β€”Parameters: ~6M
  • β€”Architecture: Lightweight BERT (4 layers, hidden size 128, 4 attention heads)
  • β€”Description: Lightweight 4-layer, 128-hidden model for emotion detection
  • β€”License: Apache-2.0 β€” free for commercial and personal use

Key Features

  • β€”βš‘ Compact Design: ~20MB footprint fits devices with limited storage.
  • β€”πŸ§  Rich Emotion Detection: Classifies 13 emotions with expressive emoji mappings.
  • β€”πŸ“Ά Offline Capability: Fully functional without internet access.
  • β€”βš™οΈ Real-Time Inference: Optimized for CPUs, mobile NPUs, and microcontrollers.
  • β€”πŸŒ Versatile Applications: Supports emotion detection, sentiment analysis, and tone analysis for short texts.

Supported Emotions

BERT-Emotion classifies text into one of 13 emotional categories, each mapped to an expressive emoji for enhanced interpretability:

EmotionEmoji
Sadness😒
Anger😠
Love❀️
Surprise😲
Fear😱
HappinessπŸ˜„
Neutral😐
Disgust🀒
ShameπŸ™ˆ
GuiltπŸ˜”
ConfusionπŸ˜•
DesireπŸ”₯
Sarcasm😏

Installation

Install the required dependencies:

bash
pip install transformers torch

Ensure your environment supports Python 3.6+ and has ~20MB of storage for model weights.

Download Instructions

  1. 1.Via Hugging Face:
  2. 2.Access the model at boltuix/bert-emotion.
  3. 3.Download the model files (~20MB) or clone the repository:
bash
     git clone https://huggingface.co/boltuix/bert-emotion
  1. 1.Via Transformers Library:
  2. 2.Load the model directly in Python:
python
     from transformers import AutoModelForSequenceClassification, AutoTokenizer
     model = AutoModelForSequenceClassification.from_pretrained("boltuix/bert-emotion")
     tokenizer = AutoTokenizer.from_pretrained("boltuix/bert-emotion")
  1. 1.Manual Download:
  2. 2.Download quantized model weights (Safetensors format) from the Hugging Face model hub.
  3. 3.Extract and integrate into your edge/IoT application.

Quickstart: Emotion Detection

Basic Inference Example

Classify emotions in short text inputs using the Hugging Face pipeline:

python
from transformers import pipeline

# Load the fine-tuned BERT-Emotion model
sentiment_analysis = pipeline("text-classification", model="boltuix/bert-emotion")

# Analyze emotion
result = sentiment_analysis("i love you")
print(result)

Output:

python
[{'label': 'Love', 'score': 0.8442274928092957}]

This indicates the emotion is Love ❀️ with 84.42% confidence.

Extended Example with Emoji Mapping

Enhance the output with human-readable emotions and emojis:

python
from transformers import pipeline

# Load the fine-tuned BERT-Emotion model
sentiment_analysis = pipeline("text-classification", model="boltuix/bert-emotion")

# Define label-to-emoji mapping
label_to_emoji = {
    "Sadness": "😒",
    "Anger": "😠",
    "Love": "❀️",
    "Surprise": "😲",
    "Fear": "😱",
    "Happiness": "πŸ˜„",
    "Neutral": "😐",
    "Disgust": "🀒",
    "Shame": "πŸ™ˆ",
    "Guilt": "πŸ˜”",
    "Confusion": "πŸ˜•",
    "Desire": "πŸ”₯",
    "Sarcasm": "😏"
}

# Input text
text = "i love you"

# Analyze emotion
result = sentiment_analysis(text)[0]
label = result["label"].capitalize()
emoji = label_to_emoji.get(label, "❓")

# Output
print(f"Text: {text}")
print(f"Predicted Emotion: {label} {emoji}")
print(f"Confidence: {result['score']:.2%}")

Output:

plaintext
Text: i love you
Predicted Emotion: Love ❀️
Confidence: 84.42%

Note: Fine-tune the model for specific domains or additional emotion categories to improve accuracy.

Evaluation

BERT-Emotion was evaluated on an emotion classification task using 13 short-text samples relevant to IoT and social media contexts. The model predicts one of 13 emotion labels, with success defined as the correct label being predicted.

Test Sentences

SentenceExpected Emotion
I love you so much!Love
This is absolutely disgusting!Disgust
I'm so happy with my new phone!Happiness
Why does this always break?Anger
I feel so alone right now.Sadness
What just happened?!Surprise
I'm terrified of this update failing.Fear
Meh, it's just okay.Neutral
I shouldn't have said that.Shame
I feel bad for forgetting.Guilt
Wait, what does this mean?Confusion
I really want that new gadget!Desire
Oh sure, like that's gonna work.Sarcasm

Evaluation Code

python
from transformers import pipeline

# Load the fine-tuned BERT-Emotion model
sentiment_analysis = pipeline("text-classification", model="boltuix/bert-emotion")

# Define label-to-emoji mapping
label_to_emoji = {
    "Sadness": "😒",
    "Anger": "😠",
    "Love": "❀️",
    "Surprise": "😲",
    "Fear": "😱",
    "Happiness": "πŸ˜„",
    "Neutral": "😐",
    "Disgust": "🀒",
    "Shame": "πŸ™ˆ",
    "Guilt": "πŸ˜”",
    "Confusion": "πŸ˜•",
    "Desire": "πŸ”₯",
    "Sarcasm": "😏"
}

# Test data
tests = [
    ("I love you so much!", "Love"),
    ("This is absolutely disgusting!", "Disgust"),
    ("I'm so happy with my new phone!", "Happiness"),
    ("Why does this always break?", "Anger"),
    ("I feel so alone right now.", "Sadness"),
    ("What just happened?!", "Surprise"),
    ("I'm terrified of this update failing.", "Fear"),
    ("Meh, it's just okay.", "Neutral"),
    ("I shouldn't have said that.", "Shame"),
    ("I feel bad for forgetting.", "Guilt"),
    ("Wait, what does this mean?", "Confusion"),
    ("I really want that new gadget!", "Desire"),
    ("Oh sure, like that's gonna work.", "Sarcasm")
]

results = []

# Run tests
for text, expected in tests:
    result = sentiment_analysis(text)[0]
    predicted = result["label"].capitalize()
    confidence = result["score"]
    emoji = label_to_emoji.get(predicted, "❓")
    results.append({
        "sentence": text,
        "expected": expected,
        "predicted": predicted,
        "confidence": confidence,
        "emoji": emoji,
        "pass": predicted == expected
    })

# Print results
for r in results:
    status = "βœ… PASS" if r["pass"] else "❌ FAIL"
    print(f"\nπŸ” {r['sentence']}")
    print(f"🎯 Expected: {r['expected']}")
    print(f"πŸ” Predicted: {r['predicted']} {r['emoji']} (Confidence: {r['confidence']:.4f})")
    print(status)

# Summary
pass_count = sum(r["pass"] for r in results)
print(f"\n🎯 Total Passed: {pass_count}/{len(tests)}")

Sample Results (Hypothetical)

  • β€”Sentence: I love you so much! Expected: Love Predicted: Love ❀️ (Confidence: 0.8442) Result: βœ… PASS
  • β€”Sentence: I feel so alone right now. Expected: Sadness Predicted: Sadness 😒 (Confidence: 0.7913) Result: βœ… PASS
  • β€”Total Passed: ~11/13 (depends on fine-tuning).

BERT-Emotion excels in classifying a wide range of emotions in short texts, particularly in IoT and social media contexts. Fine-tuning can further improve performance on nuanced emotions like Shame or Sarcasm.

Evaluation Metrics

MetricValue (Approx.)
βœ… Accuracy~90–95% on 13-class emotion tasks
🎯 F1 ScoreBalanced for multi-class classification
⚑ Latency<45ms on Raspberry Pi
πŸ“ RecallCompetitive for lightweight models

Note: Metrics vary based on hardware (e.g., Raspberry Pi 4, Android devices) and fine-tuning. Test on your target device for accurate results.

Use Cases

BERT-Emotion is designed for edge and IoT scenarios requiring real-time emotion detection for short texts. Key applications include:

  • β€”Chatbot Emotion Understanding: Detect user emotions, e.g., β€œI love you” (predicts β€œLove ❀️”) to personalize responses.
  • β€”Social Media Sentiment Tagging: Analyze posts, e.g., β€œThis is disgusting!” (predicts β€œDisgust πŸ€’β€) for content moderation.
  • β€”Mental Health Context Detection: Monitor user mood, e.g., β€œI feel so alone” (predicts β€œSadness πŸ˜’β€) for wellness apps.
  • β€”Smart Replies and Reactions: Suggest replies based on emotions, e.g., β€œI’m so happy!” (predicts β€œHappiness πŸ˜„β€) for positive emojis.
  • β€”Emotional Tone Analysis: Adjust IoT device settings, e.g., β€œI’m terrified!” (predicts β€œFear πŸ˜±β€) to dim lights for comfort.
  • β€”Voice Assistants: Local emotion-aware parsing, e.g., β€œWhy does it break?” (predicts β€œAnger πŸ˜ β€) to prioritize fixes.
  • β€”Toy Robotics: Emotion-driven interactions, e.g., β€œI really want that!” (predicts β€œDesire πŸ”₯”) for engaging animations.
  • β€”Fitness Trackers: Analyze feedback, e.g., β€œWait, what?” (predicts β€œConfusion πŸ˜•β€) to clarify instructions.

Hardware Requirements

  • β€”Processors: CPUs, mobile NPUs, or microcontrollers (e.g., ESP32-S3, Raspberry Pi 4)
  • β€”Storage: ~20MB for model weights (quantized, Safetensors format)
  • β€”Memory: ~60MB RAM for inference
  • β€”Environment: Offline or low-connectivity settings

Quantization ensures efficient memory usage, making it suitable for resource-constrained devices.

Trained On

  • β€”Custom Emotion Dataset: Curated short-text data with 13 labeled emotions (e.g., Happiness, Sadness, Love), sourced from custom datasets and chatgpt-datasets. Augmented with social media and IoT user feedback to enhance performance in chatbot, social media, and smart device contexts.

Fine-tuning on domain-specific data is recommended for optimal results.

Fine-Tuning Guide

To adapt BERT-Emotion for custom emotion detection tasks (e.g., specific chatbot or IoT interactions):

  1. 1.Prepare Dataset: Collect labeled data with 13 emotion categories.
  2. 2.Fine-Tune with Hugging Face:
python
    # !pip install transformers datasets torch --upgrade

    import torch
    from transformers import BertTokenizer, BertForSequenceClassification, Trainer, TrainingArguments
    from datasets import Dataset
    import pandas as pd

    # 1. Prepare the sample emotion dataset
    data = {
        "text": [
            "I love you so much!",
            "This is absolutely disgusting!",
            "I'm so happy with my new phone!",
            "Why does this always break?",
            "I feel so alone right now."
        ],
        "label": [2, 7, 5, 1, 0]  # Emotions: 0 to 12
    }
    df = pd.DataFrame(data)
    dataset = Dataset.from_pandas(df)

    # 2. Load tokenizer and model
    model_name = "boltuix/bert-emotion"
    tokenizer = BertTokenizer.from_pretrained(model_name)
    model = BertForSequenceClassification.from_pretrained(model_name, num_labels=13)

    # 3. Tokenize the dataset
    def tokenize_function(examples):
        return tokenizer(examples["text"], padding="max_length", truncation=True, max_length=64)

    tokenized_dataset = dataset.map(tokenize_function, batched=True)

    # 4. Manually convert all fields to PyTorch tensors (NumPy 2.0 safe)
    def to_torch_format(example):
        return {
            "input_ids": torch.tensor(example["input_ids"]),
            "attention_mask": torch.tensor(example["attention_mask"]),
            "label": torch.tensor(example["label"])
        }

    tokenized_dataset = tokenized_dataset.map(to_torch_format)

    # 5. Define training arguments
    training_args = TrainingArguments(
        output_dir="./bert_emotion_results",
        num_train_epochs=5,
        per_device_train_batch_size=2,
        logging_dir="./bert_emotion_logs",
        logging_steps=10,
        save_steps=100,
        eval_strategy="no",
        learning_rate=3e-5,
        report_to="none"  # Disable W&B auto-logging if not needed
    )

    # 6. Initialize Trainer
    trainer = Trainer(
        model=model,
        args=training_args,
        train_dataset=tokenized_dataset,
    )

    # 7. Fine-tune the model
    trainer.train()

    # 8. Save the fine-tuned model
    model.save_pretrained("./fine_tuned_bert_emotion")
    tokenizer.save_pretrained("./fine_tuned_bert_emotion")

    # 9. Example inference
    text = "I'm thrilled with the update!"
    inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=64)
    model.eval()
    with torch.no_grad():
        outputs = model(**inputs)
        logits = outputs.logits
        predicted_class = torch.argmax(logits, dim=1).item()

    labels = ["Sadness", "Anger", "Love", "Surprise", "Fear", "Happiness", "Neutral", "Disgust", "Shame", "Guilt", "Confusion", "Desire", "Sarcasm"]
    print(f"Predicted emotion for '{text}': {labels[predicted_class]}")
  1. 1.Deploy: Export the fine-tuned model to ONNX or TensorFlow Lite for edge devices.

Comparison to Other Models

ModelParametersSizeEdge/IoT FocusTasks Supported
BERT-Emotion~6M~20MBHighEmotion Detection, Classification
BERT-Lite~2M~10MBHighMLM, NER, Classification
NeuroBERT-Mini~7M~35MBHighMLM, NER, Classification
DistilBERT~66M~200MBModerateMLM, NER, Classification, Sentiment

BERT-Emotion is specialized for 13-class emotion detection, offering superior performance for short-text sentiment analysis on edge devices compared to general-purpose models like BERT-Lite, while being significantly more efficient than DistilBERT.

Emotion Classification Models Comparison Report

This report summarizes the evaluation results of various emotion classification models, including accuracy, F1 score, model size, and download links.


Summary Table

ModelAccuracyF1 ScoreSize (MB)Download URL
boltuix/bert-emotion1.001.0042.89Link
bhadresh-savani/bert-base-uncased-emotion0.800.73418.35Link
ayoubkirouane/BERT-Emotions-Classifier0.800.73418.64Link
nateraw/bert-base-uncased-emotion0.800.73417.97Link
j-hartmann/emotion-english-distilroberta-base0.800.73315.82Link
mrm8488/t5-base-finetuned-emotion0.200.07851.14Link

Best Model

πŸ† Name: boltuix/bert-emotion Accuracy: 1.00 F1 Score: 1.00 Size (MB): 42.89 Download URL: https://huggingface.co/boltuix/bert-emotion


Notes

  • β€”Very long sentences failed all the models; improvements needed.
  • β€”Model sizes are approximate based on repository file sizes.
  • β€”Accuracy and F1 scores are computed on a custom test dataset containing both short and long sentences per emotion.
  • β€”F1 Score is the weighted average.
  • β€”For more details, see the evaluation script or contact the report maintainer.

Model Variants

BoltUIX offers a range of BERT-based models tailored to different performance and resource requirements. The boltuix/bert-mobile model is optimized for mobile and edge devices, offering strong performance with the ability to quantize to ~25 MB without significant loss. Below is a summary of available models:

TierModel IDSize (MB)Notes
Microboltuix/bert-micro~15 MBSmallest, blazing-fast, moderate accuracy
Miniboltuix/bert-mini~17 MBUltra-compact, fast, slightly better accuracy
Tinyplusboltuix/bert-tinyplus~20 MBSlightly bigger, better capacity
Smallboltuix/bert-small~45 MBGood compact/accuracy balance
Midboltuix/bert-mid~50 MBWell-rounded mid-tier performance
Mediumboltuix/bert-medium~160 MBStrong general-purpose model
Largeboltuix/bert-large~365 MBTop performer below full-BERT
Proboltuix/bert-pro~420 MBUse only if max accuracy is mandatory
Mobileboltuix/bert-mobile~140 MBMobile-optimized; quantize to ~25 MB with no major loss

For more details on each variant, visit the BoltUIX Model Hub.

Tags

#BERT-Emotion #edge-nlp #emotion-detection #on-device-ai #offline-nlp #mobile-ai #sentiment-analysis #text-classification #emojis #emotions #lightweight-transformers #embedded-nlp #smart-device-ai #low-latency-models #ai-for-iot #efficient-bert #nlp2025 #context-aware #edge-ml #smart-home-ai #emotion-aware #voice-ai #eco-ai #chatbot #social-media #mental-health #short-text #smart-replies #tone-analysis

License

Apache-2.0 License: Free to use, modify, and distribute for personal and commercial purposes. See LICENSE for details.

Credits

  • β€”Base Models: boltuix/bert-mini, [boltuix/bert-mini]
  • β€”Optimized By: Boltuix, fine-tuned and quantized for edge AI applications
  • β€”Library: Hugging Face transformers team for model hosting and tools

Support & Community

For issues, questions, or contributions:

Train Your Own Emotion Detection AI in Minutes! | NeuroFeel + NeuroBERT | Hugging Face Tutorial

We welcome community feedback to enhance BERT-Emotion for IoT and edge applications!

Contact