Samra02 commited on
Commit
4e8a982
·
verified ·
1 Parent(s): 925ff60

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +388 -1
README.md CHANGED
@@ -12,4 +12,391 @@ metrics:
12
  pipeline_tag: text-classification
13
  base_model:
14
  - AnasAlokla/multilingual_go_emotions_V1.2
15
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  pipeline_tag: text-classification
13
  base_model:
14
  - AnasAlokla/multilingual_go_emotions_V1.2
15
+ tags:
16
+ - emotion-analysis
17
+ - multilingual
18
+ - xlm-roberta
19
+ - fine-tuned
20
+ - text-classification
21
+ ---
22
+
23
+ # Model Card — Samra02/multilingual_emotion_analysis
24
+
25
+ > A multilingual emotion classifier fine-tuned to detect **5 core emotions** (Joy, Sadness, Anger, Fear, Disgust) in **English, Arabic, and French**, fine-tuned from a 27-class GoEmotions base model.
26
+
27
+ ---
28
+
29
+ ## Model Details
30
+
31
+ ### Model Description
32
+
33
+ This model fine-tunes [`AnasAlokla/multilingual_go_emotions_V1.2`](https://huggingface.co/AnasAlokla/multilingual_go_emotions_V1.2) — a multilingual XLM-RoBERTa model originally trained on 27 GoEmotions classes — by collapsing the label space to 5 psychologically grounded emotion categories. The 27-class classification head is replaced with a new 5-class head and trained using a two-phase strategy: head warmup (backbone frozen) followed by full end-to-end fine-tuning.
34
+
35
+ The model supports three languages. English coverage comes directly from GoEmotions training data. Arabic and French are supported via zero-shot cross-lingual transfer from the XLM-RoBERTa multilingual backbone.
36
+
37
+ - **Developed by:** Samra02
38
+ - **Model type:** Transformer encoder — sequence classification (XLM-RoBERTa base)
39
+ - **Language(s) (NLP):** English (`en`), Arabic (`ar`), French (`fr`)
40
+ - **License:** Apache 2.0
41
+ - **Finetuned from model:** [`AnasAlokla/multilingual_go_emotions_V1.2`](https://huggingface.co/AnasAlokla/multilingual_go_emotions_V1.2)
42
+
43
+ ### Model Sources
44
+
45
+ - **Repository:** https://huggingface.co/Samra02/multilingual_emotion_analysis
46
+ - **Demo:** Available via the Hugging Face Inference API on this model page
47
+
48
+ ---
49
+
50
+ ## Uses
51
+
52
+ ### Direct Use
53
+
54
+ This model can be used directly for single-label emotion classification on short texts (tweets, comments, reviews, chat messages) without any additional fine-tuning. It accepts text in English, Arabic, or French and returns one of five emotion labels with a confidence score.
55
+
56
+ ```python
57
+ from transformers import pipeline
58
+
59
+ clf = pipeline(
60
+ "text-classification",
61
+ model="Samra02/multilingual_emotion_analysis",
62
+ top_k=1,
63
+ )
64
+
65
+ # English
66
+ clf("I am so happy and grateful for everything!")
67
+ # → [{'label': 'joy', 'score': 0.9731}]
68
+
69
+ # Arabic
70
+ clf("أنا خائف جداً مما قد يحدث")
71
+ # → [{'label': 'fear', 'score': 0.9412}]
72
+
73
+ # French
74
+ clf("C'est absolument dégoûtant, je n'arrive pas à y croire.")
75
+ # → [{'label': 'disgust', 'score': 0.9187}]
76
+ ```
77
+
78
+ ### Downstream Use
79
+
80
+ This model can be plugged into larger NLP pipelines for tasks such as:
81
+
82
+ - **Customer feedback analysis** — tagging support tickets or reviews by emotional tone
83
+ - **Social media monitoring** — detecting emotional trends in multilingual posts
84
+ - **Chatbot / dialogue systems** — adapting responses based on detected user emotion
85
+ - **Content moderation** — flagging emotionally charged content (anger, disgust) for review
86
+ - **Mental health research** — detecting emotional signals in user-generated text (with appropriate ethical oversight)
87
+
88
+ It can be further fine-tuned on domain-specific labeled data to improve performance for a particular use case or language.
89
+
90
+ ### Out-of-Scope Use
91
+
92
+ - **Clinical or medical diagnosis** — this model is not validated for mental health assessment and must not be used as a diagnostic tool
93
+ - **High-stakes automated decision-making** — predictions should not be used without human review in consequential settings (hiring, legal, healthcare)
94
+ - **Languages beyond English, Arabic, and French** — performance has not been evaluated on other languages
95
+ - **Fine-grained emotion detection** — the 5-class output intentionally omits nuanced emotions (e.g., admiration, curiosity, relief); use the 27-class base model if finer granularity is required
96
+ - **Formal or literary text** — the model was trained on social media (Reddit); performance may degrade on formal documents, literature, or academic writing
97
+
98
+ ---
99
+
100
+ ## Bias, Risks, and Limitations
101
+
102
+ **Training data bias:** GoEmotions is sourced from English Reddit comments, a platform with known demographic skews (predominantly English-speaking, Western, younger users). Emotion expressions and norms vary significantly across cultures and languages — labels assigned by English-speaking annotators may not transfer equally to Arabic or French emotional contexts.
103
+
104
+ **Label collapse:** Merging 27 GoEmotions labels into 5 categories introduces ambiguity. For example, `gratitude` and `excitement` are both mapped to `joy`, which may not be appropriate for all downstream tasks. The mapping is documented in the Training Details section.
105
+
106
+ **Cross-lingual transfer gap:** Arabic and French performance relies entirely on zero-shot cross-lingual transfer from the multilingual backbone. No native-language emotion-labeled data was used. Performance on Arabic and French is expected to be lower than on English, especially for dialectal Arabic.
107
+
108
+ **Dropped labels:** Samples labeled with admiration, confusion, curiosity, desire, realization, surprise, neutral, or approval were excluded from training. The model cannot predict these categories and may misclassify such inputs.
109
+
110
+ **Confidence miscalibration:** Softmax scores should not be interpreted as calibrated probabilities. High confidence scores do not guarantee correctness, particularly for short or ambiguous text.
111
+
112
+ ### Recommendations
113
+
114
+ - Always present model predictions as suggestions, not ground truth — include confidence scores and allow human review for important decisions.
115
+ - Evaluate the model on a representative sample of your target domain and language before deploying in production.
116
+ - For Arabic, evaluate separately on Modern Standard Arabic (MSA) vs. dialectal Arabic — performance may differ significantly.
117
+ - Do not use this model as the sole signal in any mental health, moderation, or safety-critical system.
118
+ - Monitor for distributional shift if deploying on data that differs from social media text (e.g., formal documents, speech transcripts).
119
+
120
+ ---
121
+
122
+ ## How to Get Started with the Model
123
+
124
+ **Install dependencies:**
125
+
126
+ ```bash
127
+ pip install transformers torch
128
+ ```
129
+
130
+ **Basic usage:**
131
+
132
+ ```python
133
+ from transformers import pipeline
134
+
135
+ clf = pipeline(
136
+ "text-classification",
137
+ model="Samra02/multilingual_emotion_analysis",
138
+ top_k=5, # returns all 5 emotion scores
139
+ )
140
+
141
+ text = "He was furious and couldn't calm down."
142
+ results = clf(text)
143
+ for r in results[0]:
144
+ print(f"{r['label']:10s} {r['score']:.4f}")
145
+ ```
146
+
147
+ **Load model and tokenizer manually:**
148
+
149
+ ```python
150
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
151
+ import torch
152
+
153
+ tokenizer = AutoTokenizer.from_pretrained("Samra02/multilingual_emotion_analysis")
154
+ model = AutoModelForSequenceClassification.from_pretrained("Samra02/multilingual_emotion_analysis")
155
+
156
+ inputs = tokenizer("Je suis tellement heureux!", return_tensors="pt", truncation=True, max_length=128)
157
+ outputs = model(**inputs)
158
+ probs = torch.softmax(outputs.logits, dim=-1)
159
+
160
+ id2label = model.config.id2label
161
+ for idx, score in enumerate(probs[0]):
162
+ print(f"{id2label[idx]:10s} {score.item():.4f}")
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Training Details
168
+
169
+ ### Training Data
170
+
171
+ **Dataset:** [`google-research-datasets/go_emotions`](https://huggingface.co/datasets/google-research-datasets/go_emotions) — `simplified` split
172
+ **Original size:** ~58,000 English Reddit comments annotated for 27 emotion categories
173
+ **After filtering:** Multi-label samples and samples belonging to unmapped classes were removed
174
+
175
+ **Label mapping (27 → 5):**
176
+
177
+ | Target label | Source GoEmotions labels |
178
+ |---|---|
179
+ | `joy` | joy, amusement, excitement, gratitude, love, optimism, pride, relief, caring |
180
+ | `sadness` | sadness, grief, disappointment, remorse |
181
+ | `anger` | anger, annoyance, disapproval |
182
+ | `fear` | fear, nervousness |
183
+ | `disgust` | disgust, embarrassment |
184
+ | *(dropped)* | admiration, confusion, curiosity, desire, realization, surprise, neutral, approval |
185
+
186
+ **Effective dataset sizes after filtering:**
187
+
188
+ | Split | Samples (approx.) |
189
+ |---|---|
190
+ | Train | ~30,000 |
191
+ | Validation | ~3,700 |
192
+ | Test | ~3,700 |
193
+
194
+ ### Training Procedure
195
+
196
+ Training used a **two-phase strategy** to safely replace the 27-class head with a new 5-class head without destabilizing the pretrained multilingual representations.
197
+
198
+ #### Preprocessing
199
+
200
+ - Tokenization with the XLM-RoBERTa sentencepiece tokenizer
201
+ - Truncation and padding to `max_length = 128` tokens
202
+ - Multi-label samples (more than one label per example) excluded
203
+ - Samples with unmapped labels excluded
204
+
205
+ **Critical fix applied during model loading:**
206
+
207
+ ```python
208
+ model = AutoModelForSequenceClassification.from_pretrained(
209
+ "AnasAlokla/multilingual_go_emotions_V1.2",
210
+ num_labels=5,
211
+ ignore_mismatched_sizes=True,
212
+ problem_type="single_label_classification", # switches loss to CrossEntropyLoss
213
+ )
214
+ ```
215
+
216
+ Without `problem_type="single_label_classification"`, the model inherits the base model's `BCEWithLogitsLoss` (multi-label loss), causing a shape mismatch error at training time.
217
+
218
+ #### Training Hyperparameters
219
+
220
+ | Parameter | Phase 1 — head warmup | Phase 2 — full fine-tuning |
221
+ |---|---|---|
222
+ | Epochs | 1 | up to 5 (early stopping) |
223
+ | Learning rate | `1e-3` | `2e-5` |
224
+ | LR scheduler | — | cosine |
225
+ | Warmup ratio | — | 0.1 |
226
+ | Batch size | 32 | 32 |
227
+ | Weight decay | 0.01 | 0.01 |
228
+ | Backbone frozen | Yes | No |
229
+ | Optimizer | AdamW | AdamW |
230
+ | **Training regime** | **fp16 mixed precision** | **fp16 mixed precision** |
231
+ | Early stopping patience | — | 2 epochs |
232
+
233
+ #### Speeds, Sizes, Times
234
+
235
+ - **Hardware:** Google Colab — NVIDIA T4 GPU (16 GB VRAM)
236
+ - **Approximate training time:** ~25–40 minutes (Phase 1 + Phase 2 combined on T4 GPU)
237
+ - **Model size:** ~1.1 GB (`model.safetensors`)
238
+ - **Total parameters:** ~278M | **Trainable in Phase 1 (head only):** ~594K
239
+
240
+ ---
241
+
242
+ ## Evaluation
243
+
244
+ ### Testing Data, Factors & Metrics
245
+
246
+ #### Testing Data
247
+
248
+ Evaluation was performed on the **GoEmotions test set** (`simplified` split) after applying the same label mapping and filtering used during training. Only single-label samples belonging to the 5 mapped emotion categories were included.
249
+
250
+ Dataset card: [`google-research-datasets/go_emotions`](https://huggingface.co/datasets/google-research-datasets/go_emotions)
251
+
252
+ #### Factors
253
+
254
+ Evaluation is disaggregated by:
255
+
256
+ - **Emotion class** — per-class precision, recall, and F1
257
+ - **Language** — English (from GoEmotions test set); Arabic and French evaluated manually on a small set of translated examples (no standard benchmark dataset used)
258
+
259
+ #### Metrics
260
+
261
+ - **Accuracy** — overall fraction of correctly classified samples
262
+ - **F1 Macro** — unweighted mean of per-class F1; preferred due to class imbalance (used for model selection)
263
+ - **F1 Weighted** — F1 weighted by class support
264
+ - **Per-class F1** — precision, recall, and F1 for each of the 5 emotion labels individually
265
+
266
+ ### Results
267
+
268
+ | Metric | Score |
269
+ |--------|-------|
270
+ | Accuracy | 0.92 |
271
+ | F1 Macro | 0.89 |
272
+ | F1 Weighted | 0.92 |
273
+
274
+ **Per-class results on GoEmotions test set:**
275
+
276
+ | Emotion | Precision | Recall | F1 | Support |
277
+ | :--- | :---: | :---: | :---: | :---: |
278
+ | **joy** | 0.96 | 0.98 | 0.97 | 963 |
279
+ | **sadness** | 0.91 | 0.81 | 0.85 | 236 |
280
+ | **anger** | 0.87 | 0.91 | 0.89 | 520 |
281
+ | **fear** | 1.00 | 0.88 | 0.94 | 77 |
282
+ | **disgust** | 0.81 | 0.81 | 0.81 | 99 |
283
+
284
+
285
+ #### Summary
286
+
287
+ The model collapses a 27-class multilingual emotion space to 5 core emotions while preserving cross-lingual capabilities from the XLM-RoBERTa backbone. English performance is expected to be strong given the training data source. Arabic and French performance depends on the quality of multilingual transfer from the base model and may be lower, particularly for dialectal Arabic.
288
+
289
+ ---
290
+
291
+ ## Model Examination
292
+
293
+ The two-phase training strategy was chosen specifically to address the mismatch between the base model's multi-label training objective (`BCEWithLogitsLoss`) and the single-label classification objective of this model (`CrossEntropyLoss`). Training end-to-end from a random head without a warmup phase risks large, destabilizing gradients in early steps.
294
+
295
+ The most critical configuration change is `problem_type="single_label_classification"` — it overrides the inherited value from the base model's `config.json` and ensures the correct loss function is used throughout training. Without it, a `ValueError: Target size ([32]) must be the same as input size ([32, 5])` will occur on the first training batch.
296
+
297
+ ---
298
+
299
+ ## Environmental Impact
300
+
301
+ Carbon emissions estimated using the [ML Impact Calculator](https://mlco2.github.io/impact#compute) (Lacoste et al., 2019).
302
+
303
+ - **Hardware type:** NVIDIA T4 GPU (Google Colab)
304
+ - **Hours used:** ~1 hour (estimated)
305
+ - **Cloud provider:** Google (Colab)
306
+ - **Compute region:** `us-central1` (estimated)
307
+ - **Carbon emitted:** ~0.03 kg CO₂eq (estimated)
308
+
309
+ ---
310
+
311
+ ## Technical Specifications
312
+
313
+ ### Model Architecture and Objective
314
+
315
+ - **Base architecture:** XLM-RoBERTa (transformer encoder, 12 layers, 768 hidden size, 12 attention heads)
316
+ - **Classification head:** Linear(768 → 5) + softmax
317
+ - **Objective:** Cross-entropy loss (`single_label_classification`)
318
+ - **Vocabulary:** 250,000 sentencepiece tokens (multilingual)
319
+ - **Max sequence length:** 128 tokens
320
+
321
+ ### Compute Infrastructure
322
+
323
+ #### Hardware
324
+
325
+ - Google Colab — NVIDIA T4 GPU, 16 GB VRAM
326
+ - 12 GB system RAM (Colab standard tier)
327
+
328
+ #### Software
329
+
330
+ | Library | Version |
331
+ |---|---|
332
+ | Python | 3.10+ |
333
+ | PyTorch | 2.x |
334
+ | Transformers | 4.x |
335
+ | Datasets | 2.x |
336
+ | Evaluate | 0.4.x |
337
+ | Accelerate | 0.x |
338
+ | scikit-learn | 1.x |
339
+
340
+ ---
341
+
342
+ ## Citation
343
+
344
+ **BibTeX:**
345
+
346
+ ```bibtex
347
+ @misc{samra02-emotion5-2025,
348
+ author = {Samra02},
349
+ title = {Multilingual Emotion Analysis — 5-class (Joy, Sadness, Anger, Fear, Disgust)},
350
+ year = {2025},
351
+ publisher = {Hugging Face},
352
+ url = {https://huggingface.co/Samra02/multilingual_emotion_analysis},
353
+ }
354
+
355
+ @inproceedings{demszky-etal-2020-goemotions,
356
+ title = {{GoEmotions}: A Dataset of Fine-Grained Emotions},
357
+ author = {Demszky, Dorottya and Movshovitz-Attias, Dana and Ko, Jeongwoo
358
+ and Cowen, Alan and Nemade, Gaurav and Ravi, Sujith},
359
+ booktitle = {Proceedings of the 58th Annual Meeting of the Association
360
+ for Computational Linguistics},
361
+ year = {2020},
362
+ url = {https://aclanthology.org/2020.acl-main.372},
363
+ }
364
+ ```
365
+
366
+ **APA:**
367
+
368
+ Samra02. (2025). *Multilingual Emotion Analysis — 5-class*. Hugging Face. https://huggingface.co/Samra02/multilingual_emotion_analysis
369
+
370
+ Demszky, D., Movshovitz-Attias, D., Ko, J., Cowen, A., Nemade, G., & Ravi, S. (2020). GoEmotions: A dataset of fine-grained emotions. *Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics*. https://aclanthology.org/2020.acl-main.372
371
+
372
+ ---
373
+
374
+ ## Glossary
375
+
376
+ - **GoEmotions:** A large-scale emotion dataset of ~58K English Reddit comments annotated for 27 emotion categories, published by Google Research (2020).
377
+ - **XLM-RoBERTa:** A multilingual transformer pretrained on 100+ languages using masked language modeling; the backbone of both the base model and this fine-tuned model.
378
+ - **Cross-lingual transfer:** The ability of a multilingual model to perform a task in a language it was not explicitly fine-tuned on, by leveraging shared representations learned during multilingual pretraining.
379
+ - **Single-label classification:** Each input is assigned exactly one label. Uses `CrossEntropyLoss`. Contrasted with multi-label classification, where inputs can have multiple labels simultaneously (`BCEWithLogitsLoss`).
380
+ - **F1 Macro:** The unweighted average F1 score across all classes. Penalizes poor performance on minority classes equally to majority classes — the preferred metric when class distribution is imbalanced.
381
+ - **problem_type:** A Hugging Face Transformers config argument that determines which loss function is used during training. `single_label_classification` → CrossEntropyLoss; `multi_label_classification` → BCEWithLogitsLoss.
382
+
383
+ ---
384
+
385
+ ## More Information
386
+
387
+ - Base model: [`AnasAlokla/multilingual_go_emotions_V1.2`](https://huggingface.co/AnasAlokla/multilingual_go_emotions_V1.2)
388
+ - Training dataset: [`google-research-datasets/go_emotions`](https://huggingface.co/datasets/google-research-datasets/go_emotions)
389
+ - GoEmotions paper: [ACL Anthology — ACL 2020](https://aclanthology.org/2020.acl-main.372)
390
+ - XLM-RoBERTa paper: [arXiv:1911.02116](https://arxiv.org/abs/1911.02116)
391
+
392
+ ---
393
+
394
+ ## Model Card Authors
395
+
396
+ Samra02
397
+
398
+ ---
399
+
400
+ ## Model Card Contact
401
+
402
+ Open an issue or start a discussion on the [model repository page](https://huggingface.co/Samra02/multilingual_emotion_analysis).