multilingual-emotion-classification

43
2
license:cc-by-nc-4.0
by
tabularisai
Embedding Model
OTHER
New
43 downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
Unknown
Mobile
Laptop
Server
Quick Summary

AI model with specialized capabilities.

Code Examples

How to Usepythontransformers
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model_name = "tabularisai/multilingual-emotion-classification"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
model.eval()

LABELS = ["anger", "contempt", "disgust", "fear", "frustration",
          "gratitude", "joy", "love", "neutral", "sadness", "surprise"]

@torch.no_grad()
def predict_emotions(texts, threshold: float = 0.5):
    inputs = tokenizer(texts, return_tensors="pt", truncation=True,
                       padding=True, max_length=192)
    probs = torch.sigmoid(model(**inputs).logits).cpu().numpy()
    results = []
    for row in probs:
        picked = [(LABELS[i], float(row[i])) for i in range(len(LABELS)) if row[i] >= threshold]
        picked.sort(key=lambda x: -x[1])
        results.append(picked or [("neutral", float(row[LABELS.index("neutral")]))])
    return results


texts = [
    # English
    "Thank you so much for helping me, I really appreciate it!",
    "I can't believe they cancelled the flight again, this is ridiculous.",
    # Spanish
    "¡Qué alegría verte después de tanto tiempo!",
    "Estoy muy decepcionado con el servicio.",
    # Chinese
    "收到你的礼物我真的很感动,谢谢你!",
    "这部电影太吓人了,我都不敢一个人看。",
    # Arabic
    "أنا ممتن جدًا لكل ما فعلته من أجلي.",
    "لا أستطيع تحمّل هذا الوضع أكثر من ذلك.",
    # Hindi
    "आपका यह तोहफ़ा देखकर मेरी आँखों में आँसू आ गए।",
    "यह सेवा बिल्कुल घटिया थी, मैं बहुत निराश हूँ।",
    # Japanese
    "久しぶりに会えて本当に嬉しいです!",
    "また電車が遅れた...本当にうんざりする。",
    # French
    "Je suis tellement reconnaissant pour tout ce que tu as fait.",
    "C'est inadmissible, j'en ai assez de cette situation.",
    # Swahili
    "Asante sana kwa msaada wako, nakupenda sana!",
    "Nimechoka kabisa na huduma hii mbaya.",
]

for t, r in zip(texts, predict_emotions(texts)):
    tags = ", ".join(f"{lbl}({p:.2f})" for lbl, p in r)
    print(f"Text: {t}\nEmotions: {tags}\n")
pythontransformers
from transformers import pipeline

pipe = pipeline(
    "text-classification",
    model="tabularisai/multilingual-emotion-classification",
    function_to_apply="sigmoid",
    top_k=None,
)

print(pipe("I love this product! It's amazing and works perfectly."))

Deploy This Model

Production-ready deployment in minutes

Together.ai

Instant API access to this model

Fastest API

Production-ready inference API. Start free, scale to millions.

Try Free API

Replicate

One-click model deployment

Easiest Setup

Run models in the cloud with simple API. No DevOps required.

Deploy Now

Disclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.