priyu-emotion-e5-small

A small, fast, multi-label emotion and intent classifier for chat messages in English, Hindi (Devanagari) and Hinglish (romanised Hindi mixed with English).

Base model intfloat/multilingual-e5-small (118M params)
Format ONNX, int8 dynamic quantization
Size 118 MB model + 17 MB tokenizer
Speed ~3 ms per message on a laptop CPU (Apple M-series, onnxruntime)
Output 8 independent scores (0–1), one per signal, with a tuned threshold per signal
Held-out results 95% exact match and 100% human-request recall on 500 real support messages; macro-F1 0.79 on 143 hand-written messages
Version v3: 16,529 real support messages + 5,763 GoEmotions + 3,691 synthetic

What it's for

This model is the emotional-intelligence part of priyu-ai, an open-source, single-conversation AI agent. The agent researches the web, drives a real browser, and changes how it behaves depending on the user's state of mind.

Every incoming user message is scored by two small local models in parallel, with no API calls and no keyword lists:

  1. a sentiment model (negative / neutral / positive): Horizon-Labs/multilingual-sentiment-small;
  2. this model, which says what kind of emotion or intent is present.

The agent combines these scores with conversation signals (repeated questions, failed tool calls, shouting in caps) into a smoothed frustration score. That score drives five behaviour modes: normal → concerned → frustrated → angry → human takeover. Each mode changes the agent's tone, verbosity, whether it asks questions, and whether it offers a human. When human_request fires, the agent asks the user (or calls a handover tool if the request is clear); the model alone never locks the conversation.

Signals

Signal Meaning Example
human_request asks to talk to a real person, customer care, a manager "koi insaan available hai?"
anger hostile or insulting toward the assistant or service "ekdum ghatiya jawab"
frustration things keep failing, or the user had to repeat themselves "baar baar wahi error aa raha hai"
urgency needs it now, under time pressure "my train is in 20 minutes, which platform?"
escalation refund or cancellation demand, complaint, review or legal threat "consumer forum mein complaint daal dunga"
confusion doesn't understand the answer, a term or the steps "मुझे समझ नहीं आ रहा क्या करूँ"
sarcasm positive-sounding but means the opposite "wah, kya kamaal ka jawab hai, ekdum galat"
satisfaction thankful, it worked, problem solved "badhiya, ho gaya kaam"

Signals are independent, so a message can have several ("refund do jaldi, bahut ho gaya" → escalation + urgency + frustration) or none (most ordinary messages).

Results

Two test sets, neither ever used for training, plus a Hindi check. Messages are scored one at a time, as in production. Thresholds were tuned on a validation split, never on a test set. Before training, any training message more than 0.92 cosine-similar to a test message was removed (3,444 removed).

1. Real support messages (500 messages)

  • Source: 500 real customer messages from a travel-booking support chat (WhatsApp and email), from 150 conversations. None of these conversations were used for training.
  • Labels: made by an LLM with the same definitions as the training data, not yet checked by a person.
  • Mostly ordinary: 467 of the 500 carry no signal, which is typical of real support chat.
Metric v1 (synthetic only) v2 (+ 9k real) v3 (this version)
Exact match 57% 94% 95%
Ordinary messages with no false signal 59% 98% 97%
Macro-F1 (signals present in the set) 0.25 0.51 0.62
human_request recall 25% 50% 100%

v1 had never seen real booking chat, so it flagged ordinary requests as emotional: "Bangalore to indore" came out as escalation, and "Find me a flight on 08 Dec" as urgency. v2 and v3 leave those alone.

The real set has only 33 messages that carry any signal, 2–12 per signal, so its per-signal numbers and macro-F1 are noisy. Exact match and "ordinary left alone" are the reliable figures there.

2. Hand-written test set (143 messages)

  • Written by hand before any training data existed.
    • 102 carry at least one signal, 11 carry two or three, and 41 are ordinary messages.
    • The ordinary messages include deliberate traps: "I'm human too, you know", "what's the difference between a manager and a supervisor", "how do refunds usually work on airline tickets?".
  • Language mix: 101 English, 27 Hinglish, 15 Hindi.
Metric v1 v2 v3
Macro-F1 over 8 signals 0.79 0.82 0.79
Exact match 74% 78% 76%
human_request precision / recall 78% / 95% 100% / 89% 95% / 95%
Ordinary messages with no false signal 83% 93% 93%
Median latency 2.6 ms 2.2 ms 2.4 ms
Signal (v3) Precision Recall F1 Test messages
human_request 0.95 0.95 0.95 19
anger 0.88 0.50 0.64 14
frustration 0.68 0.75 0.71 20
urgency 1.00 0.62 0.77 16
escalation 0.91 0.83 0.87 12
confusion 0.83 0.77 0.80 13
sarcasm 0.86 0.67 0.75 9
satisfaction 0.83 0.91 0.87 11

3. Hindi check: BRIGHTER (4,776 messages)

The Hindi part of BRIGHTER, human-written and human-labelled, used only for testing. Only its anger label matches one of ours.

v2 v3
Anger precision 53% 55%
Anger recall 29% 35%

Low recall is expected. BRIGHTER's anger is mostly about news, politics or life events, while ours is anger aimed at the assistant or the service.

Which data helped (same real test set)

Training data Real macro-F1 Real human recall Hindi anger recall
synthetic + 9k real (v2) 0.51 50% 29%
synthetic + 16.5k real 0.59 75% 14%
synthetic + 16.5k real + GoEmotions (v3) 0.62 100% 35%

We left out MELD and DailyDialog: their licenses (GPL-3.0, CC BY-NC-SA) don't suit a model published under MIT, and their labels (fear, sadness, surprise…) don't match our signals.

Compared with other approaches (hand-written set)

Approach Macro-F1 Human-request recall Size Speed
Keyword / regex lists (EN + HI + Hinglish) 0.56 37% — <1 ms
Frozen e5-small + logistic regression 0.65 89% 118 MB 2 ms
Frozen e5-base + logistic regression 0.74 89% 280 MB 5 ms
Frozen gte-multilingual-base + logistic regression 0.73 95% 340 MB 5 ms
Fine-tuned e5-small v3 0.79 95% 118 MB 2 ms

Example mistakes (hand-written set)

Message Expected Predicted
"is anyone real working there?" human_request —
"what a joke of an assistant" anger frustration
"who built this garbage" anger —
"my train is in 20 minutes, which platform?" urgency —
"I'm leaving a one-star review" escalation —
"great, now it's even worse, thanks a lot" sarcasm, frustration satisfaction
"I'm human too, you know" — human_request
"explain how chargebacks work" — confusion

Training data

25,983 messages in total (22,539 after the leakage guard), from three sources.

Real customer-support messages (16,529, not released)

  • Source: customer messages from a travel-booking support service (flights, refunds, check-in), October–December 2026. 99% WhatsApp, 1% email.
  • Labels: made offline by LLMs with written definitions of each signal: about half by Google Gemini (backend/training/label_real.py) and half by Anthropic Claude. The 557 rows marked as uncertain were left out.
  • Not released: these messages are private customer data and are not part of the repo or this model repo; only the trained weights are published.
  • Composition: 14,632 carry no signal (89%, as in real chat), so most of what they teach is what is not an emotion in everyday booking chat (routes, dates, prices, passenger details, yes/no).
    • Signals: frustration 684, urgency 366, escalation 271, human_request 251, satisfaction 220, anger 207, confusion 113, sarcasm 12.

GoEmotions subset (5,763)

From GoEmotions (Reddit comments, human-labelled, Apache 2.0). Only comments whose every emotion maps cleanly to one of ours were kept:

GoEmotions label Our signal Examples
anger anger 1,200
annoyance frustration 1,200
confusion confusion 875
gratitude, relief satisfaction 1,088
neutral no signal 1,400

npm run emotion:public rebuilds this subset (backend/training/prepare_public.py).

Synthetic messages (3,691, in the repo)

Generated once, offline, with Google Gemini (gemini-3.5-flash-lite). They are in the GitHub repo: backend/training/data/train.json. Gemini only wrote and labelled training data; the model runs fully locally.

Label Examples
frustration 598
escalation 490
urgency 487
human_request 460
confusion 435
anger 414
sarcasm 350
satisfaction 296
no signal (ordinary + hard negatives) 630
messages with 2 signals 469
  • Languages (approximate): 1,312 English, 1,427 Hinglish, 952 Hindi in Devanagari.
  • Length: 12 words on average, from 1-word texts to 30-word messages with context.

How it was generated:

  1. Per signal: a short definition, about ten everyday domains (travel, shopping, phones and apps, food, banking, studies, jobs, trains and flights, health appointments, events), and six writing styles: very short texting, medium, long with context, messy WhatsApp style with typos, formal, and mixed.
  2. Very short Hinglish and Hindi texting: 1–5 words with slang ("yaar", "bhai", "arre"), added after the first version missed short messages.
  3. Two-signal messages, e.g. human_request + anger, frustration + urgency, escalation + urgency, sarcasm + frustration.
  4. Hard negatives: ordinary messages that mention trigger topics without the emotion, e.g. refund policies, "my manager asked me…", "urgent care", movie reviews calling something "terrible", and calm imperatives like "send the link again".
  5. Deduplication: case-insensitive.

Training procedure

Architecture e5-small encoder → mean pooling → dropout 0.1 → linear layer (384 → 8)
Input "query: " + message, max 48 tokens
Loss binary cross-entropy per signal, positive weights clipped to 1–6
Frozen word-embedding table (250k-token vocabulary); 21.4M of 117.7M parameters trained
Optimiser AdamW (weight decay 0.01), one-cycle LR: 4e-5 encoder, 1e-3 head
Schedule 6 epochs, batch 32, best epoch by validation macro-F1 (10% split)
Thresholds one per signal, chosen on validation (accuracy + ½·F1)
Hardware / time MacBook Air (Apple silicon, MPS), about 18 minutes
Validation macro-F1 0.81

Quantization: dynamic int8 (118 MB, 3 ms) was compared with weight-only int8 (409 MB, 15 ms). Their accuracy was similar, so dynamic int8 was chosen.

Files

File
model_int8.onnx the classifier. Inputs input_ids, attention_mask (int64); output logits [batch, 8]
tokenizer.json XLM-R SentencePiece tokenizer (from e5-small)
config.json labels, input prefix, max length, per-signal thresholds, held-out metrics

Usage

import json, numpy as np, onnxruntime as ort
from tokenizers import Tokenizer

cfg = json.load(open("config.json"))
tok = Tokenizer.from_file("tokenizer.json"); tok.enable_truncation(cfg["max_length"])
sess = ort.InferenceSession("model_int8.onnx")

def emotions(text: str) -> dict:
    enc = tok.encode(cfg["prefix"] + text)
    logits = sess.run(None, {"input_ids": np.array([enc.ids]), "attention_mask": np.array([enc.attention_mask])})[0][0]
    scores = dict(zip(cfg["labels"], (1 / (1 + np.exp(-logits))).round(3)))
    return {"detected": [l for l, p in scores.items() if p >= cfg["thresholds"][l]], "scores": scores}

print(emotions("yaar kitni baar bolu, abhi tak nahi hua"))   # → frustration
print(emotions("koi insaan hai kya wahan"))                   # → human_request

Download with huggingface_hub (hf download sahil281203/priyu-emotion-e5-small) or the plain resolve/main/<file> URLs. Score messages one at a time: the int8 model quantizes activations per call, so batching shifts scores slightly.

Intended use and limitations

Intended for: adapting a chatbot or support assistant's tone and next step; routing or prioritising conversations; dashboards of customer emotion in English, Hindi or Hinglish chat.

Not intended for: clinical, mental-health or safety-critical judgements; decisions about people (hiring, credit, moderation bans); automatic actions without confirmation. In particular, treat human_request as a prompt to confirm with the user.

Known limitations:

  • One domain of real data. The real messages all come from travel-booking support. Other domains (shopping, banking) are covered by synthetic and GoEmotions data only.
  • LLM labels. The synthetic data and the real messages were labelled by LLMs; neither has been fully checked by a person yet.
  • Anger is often read as frustration ("what a joke of an assistant", "tum kisi kaam ke nahi ho"): anger recall is 0.50 on the hand-written set. The agent's frustration score still rises, so the behaviour is similar.
  • Urgency stated as a fact is missed ("my train is in 20 minutes", "need it in the next ten minutes").
  • Threats of a review or social-media post are sometimes missed ("I'm leaving a one-star review").
  • Sarcasm is rare in real support chat (12 examples) and can still read as satisfaction.
  • The hand-written test set is English-heavy (101 of 143), and the real test set has few emotional messages (33 of 500), so per-signal numbers are noisy.
  • Each message is scored in isolation. Conversation context (repeated questions, failed actions) is handled by the agent, not the model.

Reproduce or improve

git clone https://github.com/sahil28123/priyu-ai && cd priyu-ai
npm run setup && npm run setup:train   # app + PyTorch for training
npm run emotion:data                   # optional: generate more synthetic examples (needs GEMINI_API_KEY)
npm run emotion:label                  # optional: label your own messages in backend/training/data/private/
npm run emotion:public                 # GoEmotions subset + BRIGHTER Hindi check
npm run emotion:train                  # ~3-20 min; installs only if it beats the current model
npm run emotion:eval                   # score on the held-out test set

License and acknowledgements

  • MIT, like the base model intfloat/multilingual-e5-small.
  • Synthetic training examples were generated with Google Gemini; real messages were labelled with Google Gemini and Anthropic Claude.
  • GoEmotions (Demszky et al., 2020), Apache 2.0.
  • BRIGHTER (Muhammad et al., 2025), CC-BY-4.0, used for evaluation only.
  • Real messages: customer-support conversations, used with the operator's permission and not redistributed.
  • Built for priyu-ai.
Downloads last month
22
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for sahil281203/priyu-emotion-e5-small

Quantized
(334)
this model