Project04

EmoC

Gallery
Architecture Diagram
Training Pipeline
Results Chart
System Overview

Emotion Intelligence System — real-time emotion recognition and prediction.

Overview

EmoC is an end-to-end emotion intelligence system that classifies text into emotional categories and provides interactive prediction capabilities. The system combines transformer-based classification with a user-facing interactive demo.

Problem

Emotion detection in text is fundamental to understanding human communication. However, existing solutions are either too broad (positive/negative only), too slow for interactive use, or lack interpretability. EmoC addresses all three gaps.

Architecture

`

Input Text → Tokenizer → Transformer Encoder → Classification Head → Emotion Label

Attention Weights

Interpretation Layer

`

Emotion Categories

The system classifies text into 7 distinct emotions based on dimensional affect theory:

CategoryDescriptionValence-Arousal
----------------------------------------
JoyPositive, high-arousal+1, +1
SadnessNegative, low-arousal-1, -1
AngerNegative, high-arousal-1, +1
FearNegative, low-to-medium arousal-1, +0.5
SurpriseNeutral, high-arousal0, +1
DisgustNegative, medium arousal-1, 0
NeutralLow arousal, neutral valence0, 0

Model Architecture

  • Base Model: Fine-tuned BERT-base (uncased)
  • Classification Head: Linear(768, 256) → ReLU → Dropout(0.3) → Linear(256, 7)
  • Attention Head: Extracts attention weights from layer 8 for interpretability
  • Token-Level Classification: Average pooling over token embeddings before classification
  • Training Configuration

    ParameterValue
    ------------------
    Base Modelbert-base-uncased
    OptimizerAdamW (lr=2e-5, weight_decay=0.01)
    SchedulerLinear warmup (10%) + linear decay
    Epochs5
    Batch Size32
    Max Sequence Length128
    Dropout0.3
    HardwareSingle NVIDIA T4 (Google Colab)
    Training Time~2.5 hours

    Dataset

    Primary Dataset: GoEmotions (Google Research)

  • 58,000 Reddit comments
  • 27 emotion categories (mapped to 7 core emotions)
  • Balanced through oversampling of underrepresented classes
  • Preprocessing:

  • Removing HTML and markdown artifacts
  • Lowercasing (BERT uncased compatibility)
  • Truncating sequences >128 tokens
  • Handling class imbalance with weighted sampling
  • Train/Val/Test split: 80/10/10
  • Augmentation:

  • Synonym replacement (WordNet)
  • Random deletion (p=0.1)
  • Back-translation for minority classes
  • Emotion Classification

    Classification Head

    The classification head is a simple feed-forward network:

    `

    Pooled Output (768) → Dense(256) → ReLU → Dropout(0.3) → Dense(7) → Softmax

    `

    Multi-Label Extension

    While the primary task is single-label classification, the system also supports multi-label outputs where text can express blended emotions. This is achieved through a secondary sigmoid-based head.

    Interpretability

    EmoC provides attention-based explanations:

  • Highlights tokens that most influenced the classification
  • Shows attention weight distribution across layers
  • Visualizes which words pushed toward each emotion category
  • Training

    Training Process

  • Warmup: 500 steps of linear learning rate increase to 2e-5
  • Fine-tuning: 5 epochs with batch size 32
  • Gradient clipping: Max norm of 1.0 to prevent exploding gradients
  • Checkpointing: Save best model based on validation macro-F1
  • Early stopping: Patience of 2 epochs, monitored on validation loss
  • Loss Function

    Label-smoothed cross-entropy with smoothing parameter ε=0.1. This prevents the model from becoming overconfident and improves generalization to unseen emotional expressions.

    Evaluation

    Results

    MetricValue
    ---------------
    Accuracy72.4%
    Macro F168.1%
    Weighted F171.8%
    Per-Class F1 (avg)66.3%
    Confusion MatrixSee below

    Per-Class Performance

    EmotionPrecisionRecallF1
    ---------------------------------
    Joy0.780.710.74
    Sadness0.690.740.71
    Anger0.730.680.70
    Fear0.640.620.63
    Surprise0.710.750.73
    Disgust0.680.660.67
    Neutral0.740.730.73

    Error Analysis

  • Joy ↔ Surprise: Confused when surprise is positive and high-arousal
  • Anger ↔ Disgust: Overlapping negative high-arousal features
  • Fear ↔ Sadness: Both low-valence emotions with subtle arousal differences
  • Applications

  • Customer service: Detect customer frustration in real-time
  • Mental health: Monitor emotional state in therapy chatbots
  • Content moderation: Flag emotionally charged content
  • Education: Adapt content difficulty based on student emotional state
  • Market research: Analyze sentiment in product reviews at the emotion level
  • Interactive Prediction Demo

    The system includes a live demo where users can:

  • Type or paste text
  • See real-time emotion classification with confidence scores
  • View attention visualization highlighting influential words
  • Compare predictions across emotion categories
  • Submit feedback to improve model performance
  • The demo is powered by a fast inference server with cached model embeddings for sub-100ms response times.

    Lessons Learned

  • BERT is a strong baseline: Fine-tuning BERT-base for emotion classification is surprisingly effective without custom architectures.
  • GoEmotions is noisy: Human annotation of emotions has inherent ambiguity — don't expect >80% accuracy on fine-grained categories.
  • Attention is not always trustworthy: Layer 8 attention weights correlate well with final predictions but can be misleading for some examples.
  • Class imbalance is critical: Weighted sampling improved macro F1 by 8% over uniform sampling.
  • Interpretability drives trust: Users prefer models that show attention highlights over black-box predictions.
  • Future Work

  • Extend to multilingual emotion recognition
  • Add emotion dynamics tracking across conversations
  • Integrate visual cues (facial expression) for multimodal emotion detection
  • Explore emotion causality — what causes specific emotional shifts in text
  • Build a real-time API with WebSocket streaming support
  • Source Code

    GitHub Repository

    Sivadeth PS — AI Engineer