text-classification · 128.99 MB WASM q8 (125.43 MB weights) · 4-Class TweetEval · RoBERTa-base

Twitter-RoBERTa Emotion — 4-Class TweetEval Social Classifier

cardiffnlp/twitter-roberta-base-emotion is a RoBERTa-base encoder pretrained on ~58M tweets and fine-tuned on the TweetEval Emotion benchmark (SemEval-2018 Task 1, arXiv:2010.12421) for 4 emotion classes (joy, optimism, anger, sadness). Loaded via onnx-community/twitter-roberta-base-emotion-ONNX (q8 WASM), it runs entirely off the main thread with live @user/http normalization comparison and real BPE token inspection.

Upstream Model cardiffnlp/twitter-roberta-base-emotion
ONNX Build onnx-community/twitter-roberta-base-emotion-ONNX
Pipeline Task text-classification
Download & Quant 128.99 MB (125.43 MB q8) · WASM
4-Class TweetEval Mapping 0: anger · 1: joy · 2: optimism · 3: sadness Auto-corrected from Hub config.json (0: joy · 1: optimism · 2: anger · 3: sadness)
License & Citation Unspecified upstream (TweetEval · arXiv:2010.12421)

1. Live 4-Emotion Classifier & CardiffNLP Preprocessing Inspector

Why @user / http normalization matters: TweetEval trained cardiffnlp/twitter-roberta-base-emotion with handles replaced by @user and links replaced by http. Toggle the normalizer below to compare exact Normalized vs Raw 4-class probabilities, softmax margin, and real Byte-Level BPE token chips.
Upstream config.json label bug (auto-corrected to TweetEval mapping.txt): Upstream commit dff452c4 (2022-03-23) erroneously wrote {0: "joy", 1: "optimism", 2: "anger", 3: "sadness"} into config.json (HF Discussion #1), and the ONNX conversion inherited it — even though the classifier head weights and CardiffNLP's own README Python script use TweetEval's canonical mapping.txt (0: anger · 1: joy · 2: optimism · 3: sadness). Our worker inspects live model.config.id2label at load time and applies mapping.txt when the scrambled permutation is present, surfacing both raw config.json and canonical labels below.

Pick a tweet/social preset, edit text, paste anywhere, or drop/upload a .txt, .md, .csv, or .json file:

Calls pipeline("text-classification", "onnx-community/twitter-roberta-base-emotion-ONNX", { device: "wasm", dtype: "q8" }) with { top_k: 4 } via shared Transformers.js 3.7.5 inside a dedicated Web Worker.

Drop a .txt, .md, .csv, or .json file here, paste from clipboard, or choose a file.

Dominant emotion–
Top confidence–
Softmax margin (T1−T2)–
Shannon entropy–
Latency (2 passes)–
BPE tokens · NaN check–

Active Run · 4-Class Emotion Distribution

Initialize the model above to score this social post.

Valence balance (joy + optimism) − (anger + sadness) will appear after inference.

Live model.config.id2label vs TweetEval mapping.txt status will appear after inference.

Preprocessing Side-by-Side (@user / http)

Waiting for run to compare normalized vs raw input.
RAW TEXT
–
CARDIFFNLP NORMALIZED
–

Alternate mode probabilities will appear here.

See Inside · Byte-Level BPE Token Chips (Real pipe.tokenizer Output)

Displays exact <s>, </s>, @user/http anchors, BPE subword pieces, and token IDs.

Run inference to inspect real RoBERTa Byte-Level BPE tokens.

2. Why 4-Class Social Emotion Matters & Use-Case Ladder

Sentiment polarity lumps constructive hope together with sarcasm or lumps grief together with outrage. Separating joy, optimism, anger, and sadness in a 125.43 MB quantized browser encoder unlocks private client-side workflows:

Show the code · emotion-core.mjs — preprocessTwitterText(), resolveEmotionMapping() & normalizeEmotionScores()
Show the code · worker.js — inspectBpeTokens(), clipToMaxBpeTokens(), runSingleClassify() & classify()

3. How the API Works & References

import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.5";

const classifier = await pipeline(
  "text-classification",
  "onnx-community/twitter-roberta-base-emotion-ONNX",
  { device: "wasm", dtype: "q8" },
);

// Raw ONNX config.json has {0: "joy", 1: "optimism", 2: "anger", 3: "sadness"};
// TweetEval weights & mapping.txt use {0: "anger", 1: "joy", 2: "optimism", 3: "sadness"}.
const TWEETEVAL_FIX = { joy: "anger", optimism: "joy", anger: "optimism", sadness: "sadness" };
const raw = await classifier("Celebrating my promotion 😎", { top_k: 4 });
const scores = raw.map((r) => ({ ...r, label: TWEETEVAL_FIX[r.label] ?? r.label }));
// -> [{ label: "joy", score: ~0.940 }, { label: "optimism", score: ~0.035 }, ...]

References: cardiffnlp/twitter-roberta-base-emotion · onnx-community/twitter-roberta-base-emotion-ONNX · TweetEval emotion/mapping.txt · HF Discussion #1 (config.json id2label bug) · TweetEval Paper (Barbieri et al., EMNLP 2020) · TweetEval GitHub · Browser requirements: WebAssembly + Web Workers + Cache Storage (Baseline Widely Available; no WebGPU required).