Adapters
adapters
mad-x
emotion-detection
multi-label-classification
multilingual
low-resource
xlm-roberta
Instructions to use MominaMahmood/All-Emotion-Adapters with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Adapters
How to use MominaMahmood/All-Emotion-Adapters with Adapters:
from adapters import AutoAdapterModel model = AutoAdapterModel.from_pretrained("<base-model-id>") model.load_adapter("MominaMahmood/All-Emotion-Adapters", set_active=True) - Notebooks
- Google Colab
- Kaggle
Upload README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: adapter-transformers
|
| 3 |
+
tags:
|
| 4 |
+
- adapters
|
| 5 |
+
- mad-x
|
| 6 |
+
- emotion-detection
|
| 7 |
+
- multi-label-classification
|
| 8 |
+
- multilingual
|
| 9 |
+
- low-resource
|
| 10 |
+
- xlm-roberta
|
| 11 |
+
base_model:
|
| 12 |
+
- FacebookAI/xlm-roberta-large
|
| 13 |
+
- UBC-NLP/serengeti-E250
|
| 14 |
+
datasets:
|
| 15 |
+
- brighter-dataset/BRIGHTER-emotion-categories
|
| 16 |
+
language:
|
| 17 |
+
- en
|
| 18 |
+
- hi
|
| 19 |
+
- ru
|
| 20 |
+
- ha
|
| 21 |
+
- rw
|
| 22 |
+
- su
|
| 23 |
+
- yo
|
| 24 |
+
- vmw
|
| 25 |
+
- pcm
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
# All Emotion Adapters: MAD-X adapters for multilingual emotion detection
|
| 29 |
+
|
| 30 |
+
Trained MAD-X adapters from my MSc dissertation, **"Multilingual Models Have Feelings Too?"**
|
| 31 |
+
(MSc Applied Artificial Intelligence, University of Huddersfield, 2026).
|
| 32 |
+
|
| 33 |
+
They detect six emotions in text as a **multi-label** task (a text can have several emotions, or none):
|
| 34 |
+
|
| 35 |
+
`anger, disgust, fear, joy, sadness, surprise`
|
| 36 |
+
|
| 37 |
+
They cover 9 languages across three resource levels, from the BRIGHTER dataset (SemEval-2025 Task 11):
|
| 38 |
+
|
| 39 |
+
| Tier | Languages (code) |
|
| 40 |
+
|---|---|
|
| 41 |
+
| High resource | English (`eng`), Hindi (`hin`), Russian (`rus`) |
|
| 42 |
+
| Mid resource | Hausa (`hau`), Kinyarwanda (`kin`), Sundanese (`sun`) |
|
| 43 |
+
| Low resource | Yoruba (`yor`), Emakhuwa (`vmw`), Nigerian Pidgin (`pcm`) |
|
| 44 |
+
|
| 45 |
+
- **Dissertation code and results:** https://github.com/Momina0398/EmotionDetection
|
| 46 |
+
- **API that serves these adapters (FastAPI, Docker, CI):** https://github.com/Momina0398/emotion-api
|
| 47 |
+
|
| 48 |
+
## What is in this repo
|
| 49 |
+
|
| 50 |
+
```
|
| 51 |
+
adapters_xlmr_weighted/ 47 runs on xlm-roberta-large (all 9 languages)
|
| 52 |
+
adapters_serengeti/ 26 runs on UBC-NLP/serengeti-E250 (5 African languages)
|
| 53 |
+
lang_sun_lapt/ Sundanese language adapter, extra pre-training (LAPT)
|
| 54 |
+
lang_vmw_lapt/ Emakhuwa language adapter, LAPT, xlm-roberta-large
|
| 55 |
+
lang_vmw_lapt_serengeti/ Emakhuwa language adapter, LAPT, SERENGETI
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
Each run folder is named `<lang>_track_<a|c>_<C1|C2|C3>` and contains three parts:
|
| 59 |
+
|
| 60 |
+
```
|
| 61 |
+
lang/ language adapter (invertible MAD-X language adapter)
|
| 62 |
+
task/ emotion task adapter ("emotion_task")
|
| 63 |
+
head/ 6-label multi-label classification head
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
**Track**
|
| 67 |
+
- `track_a`: target-language training data was available (supervised)
|
| 68 |
+
- `track_c`: no target-language training data (cross-lingual transfer only)
|
| 69 |
+
|
| 70 |
+
**Source configuration** (which languages the task adapter was trained on)
|
| 71 |
+
- `C1`: all other BRIGHTER languages
|
| 72 |
+
- `C2`: languages in the same top-level family as the target
|
| 73 |
+
- `C3`: languages in the same sub-family as the target
|
| 74 |
+
|
| 75 |
+
Some combinations are missing on purpose. When a family or sub-family pool was too small to form a valid training set, that run was not created rather than filled with an invented pool.
|
| 76 |
+
|
| 77 |
+
## How to use
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
# pip install adapters==1.3.0 transformers torch huggingface_hub
|
| 81 |
+
import torch
|
| 82 |
+
from huggingface_hub import snapshot_download
|
| 83 |
+
from transformers import AutoTokenizer
|
| 84 |
+
from adapters import AutoAdapterModel
|
| 85 |
+
import adapters.composition as ac
|
| 86 |
+
|
| 87 |
+
REPO = "MominaMahmood/All-Emotion-Adapters"
|
| 88 |
+
RUN = "adapters_xlmr_weighted/rus_track_a_C1"
|
| 89 |
+
BASE = "xlm-roberta-large" # use "UBC-NLP/serengeti-E250" for adapters_serengeti runs
|
| 90 |
+
LABELS = ["anger", "disgust", "fear", "joy", "sadness", "surprise"]
|
| 91 |
+
|
| 92 |
+
path = snapshot_download(REPO, allow_patterns=[f"{RUN}/*"])
|
| 93 |
+
run = f"{path}/{RUN}"
|
| 94 |
+
|
| 95 |
+
tok = AutoTokenizer.from_pretrained(BASE)
|
| 96 |
+
model = AutoAdapterModel.from_pretrained(BASE)
|
| 97 |
+
model.load_adapter(f"{run}/lang", load_as="lang")
|
| 98 |
+
model.load_adapter(f"{run}/task", load_as="emotion_task")
|
| 99 |
+
model.load_head(f"{run}/head")
|
| 100 |
+
model.set_active_adapters(ac.Stack("lang", "emotion_task"))
|
| 101 |
+
model.eval()
|
| 102 |
+
|
| 103 |
+
texts = ["Я так рада тебя видеть!"]
|
| 104 |
+
enc = tok(texts, padding=True, truncation=True, max_length=256, return_tensors="pt")
|
| 105 |
+
with torch.no_grad():
|
| 106 |
+
probs = torch.sigmoid(model(**enc).logits)[0].tolist()
|
| 107 |
+
print({e: round(p, 3) for e, p in zip(LABELS, probs)})
|
| 108 |
+
print("labels:", [e for e, p in zip(LABELS, probs) if p >= 0.5])
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
Use a threshold of **0.5** per label, as in training and evaluation.
|
| 112 |
+
|
| 113 |
+
## Training details
|
| 114 |
+
|
| 115 |
+
| Setting | Value |
|
| 116 |
+
|---|---|
|
| 117 |
+
| Architecture | MAD-X: language adapter + task adapter stacked on a frozen backbone |
|
| 118 |
+
| Backbones | `xlm-roberta-large`, `UBC-NLP/serengeti-E250` |
|
| 119 |
+
| Adapter configs | `SeqBnInvConfig` (language), `SeqBnConfig` (task), reduction factor 16 |
|
| 120 |
+
| Loss | Binary cross-entropy with per-label positive class weights ("weighted") |
|
| 121 |
+
| Learning rate | 5e-5 |
|
| 122 |
+
| Batch size | 8 |
|
| 123 |
+
| Max epochs | 10, early stopping with patience 3 on the dev split |
|
| 124 |
+
| Max sequence length | 256 |
|
| 125 |
+
| Library | `adapters` 1.3.0 |
|
| 126 |
+
| LAPT | Extra masked-language-model training of the language adapter for Emakhuwa (Emakhuwa text) and Sundanese (Javanese and Indonesian text) |
|
| 127 |
+
|
| 128 |
+
Model selection used the validation split only. Full results, significance tests and per-language analysis are in the dissertation repo linked above.
|
| 129 |
+
|
| 130 |
+
## Limitations
|
| 131 |
+
|
| 132 |
+
- **English has no disgust labels** in the BRIGHTER training data, so English runs cannot learn that emotion. Treat English disgust scores as meaningless.
|
| 133 |
+
- **Single random seed.** Results do not capture variation between training runs.
|
| 134 |
+
- **Emotion labels are dataset annotations**, not ground truth about how a writer feels.
|
| 135 |
+
- Performance on the low-resource languages (especially Emakhuwa and Nigerian Pidgin) is well below the high-resource languages.
|
| 136 |
+
- A main finding of the dissertation is that **sub-family transfer (C3) did not beat broader source pools**. For most languages, pick C1 or C2 first.
|
| 137 |
+
- **Not for high-stakes decisions about individuals** (for example health, hiring or policing) without expert human review.
|
| 138 |
+
|
| 139 |
+
## Citation
|
| 140 |
+
|
| 141 |
+
If you use these adapters, please cite the dissertation:
|
| 142 |
+
|
| 143 |
+
```
|
| 144 |
+
Siddiq, M. M. (2026). Multilingual Models Have Feelings Too? Culturally Aware
|
| 145 |
+
Sub-Family Transfer for Emotion Detection. MSc dissertation, University of Huddersfield.
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
Please also cite the BRIGHTER dataset and SemEval-2025 Task 11 papers.
|