Update README.md
Browse files
README.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
license:
|
| 4 |
base_model: FacebookAI/xlm-roberta-base
|
| 5 |
tags:
|
| 6 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
metrics:
|
| 8 |
- f1
|
| 9 |
- precision
|
|
@@ -11,64 +17,260 @@ metrics:
|
|
| 11 |
model-index:
|
| 12 |
- name: clapAI/roberta-base-multilingual-sentiment
|
| 13 |
results: []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
---
|
| 15 |
|
| 16 |
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
| 17 |
should probably proofread and complete it, then remove this comment. -->
|
| 18 |
|
| 19 |
-
# clapAI/
|
| 20 |
|
| 21 |
-
|
| 22 |
-
It achieves the following results on the evaluation set:
|
| 23 |
-
- Loss: 0.4341
|
| 24 |
-
- F1: 0.8169
|
| 25 |
-
- Precision: 0.8176
|
| 26 |
-
- Recall: 0.8163
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
## Training procedure
|
| 41 |
|
| 42 |
### Training hyperparameters
|
| 43 |
|
| 44 |
The following hyperparameters were used during training:
|
| 45 |
-
- learning_rate: 5e-05
|
| 46 |
-
- train_batch_size: 512
|
| 47 |
-
- eval_batch_size: 512
|
| 48 |
-
- seed: 42
|
| 49 |
-
- distributed_type: multi-GPU
|
| 50 |
-
- gradient_accumulation_steps: 2
|
| 51 |
-
- total_train_batch_size: 1024
|
| 52 |
-
- optimizer: Use adamw_torch_fused with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
|
| 53 |
-
- lr_scheduler_type: cosine
|
| 54 |
-
- lr_scheduler_warmup_ratio: 0.01
|
| 55 |
-
- num_epochs: 5.0
|
| 56 |
-
- mixed_precision_training: Native AMP
|
| 57 |
-
|
| 58 |
-
### Training results
|
| 59 |
-
|
| 60 |
-
| Training Loss | Epoch | Step | Validation Loss | F1 | Precision | Recall |
|
| 61 |
-
|:-------------:|:-----:|:-----:|:---------------:|:------:|:---------:|:------:|
|
| 62 |
-
| 0.893 | 1.0 | 3074 | 0.4333 | 0.8038 | 0.8076 | 0.8022 |
|
| 63 |
-
| 0.8335 | 2.0 | 6148 | 0.4180 | 0.8150 | 0.8152 | 0.8149 |
|
| 64 |
-
| 0.7149 | 3.0 | 9222 | 0.4238 | 0.8162 | 0.8168 | 0.8158 |
|
| 65 |
-
| 0.7298 | 4.0 | 12296 | 0.4258 | 0.8168 | 0.8178 | 0.8160 |
|
| 66 |
-
| 0.6729 | 5.0 | 15370 | 0.4341 | 0.8169 | 0.8176 | 0.8163 |
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
### Framework versions
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
license: apache-2.0
|
| 4 |
base_model: FacebookAI/xlm-roberta-base
|
| 5 |
tags:
|
| 6 |
+
- sentiment
|
| 7 |
+
- text-classification
|
| 8 |
+
- multilingual
|
| 9 |
+
- modernbert
|
| 10 |
+
- sentiment-analysis
|
| 11 |
+
- product-reviews
|
| 12 |
+
- place-reviews
|
| 13 |
metrics:
|
| 14 |
- f1
|
| 15 |
- precision
|
|
|
|
| 17 |
model-index:
|
| 18 |
- name: clapAI/roberta-base-multilingual-sentiment
|
| 19 |
results: []
|
| 20 |
+
datasets:
|
| 21 |
+
- clapAI/MultiLingualSentiment
|
| 22 |
+
language:
|
| 23 |
+
- en
|
| 24 |
+
- zh
|
| 25 |
+
- vi
|
| 26 |
+
- ko
|
| 27 |
+
- ja
|
| 28 |
+
- ar
|
| 29 |
+
- de
|
| 30 |
+
- es
|
| 31 |
+
- fr
|
| 32 |
+
- hi
|
| 33 |
+
- id
|
| 34 |
+
- it
|
| 35 |
+
- ms
|
| 36 |
+
- pt
|
| 37 |
+
- ru
|
| 38 |
+
- tr
|
| 39 |
+
pipeline_tag: text-classification
|
| 40 |
---
|
| 41 |
|
| 42 |
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
| 43 |
should probably proofread and complete it, then remove this comment. -->
|
| 44 |
|
| 45 |
+
# clapAI/modernBERT-base-multilingual-sentiment
|
| 46 |
|
| 47 |
+
## Introduction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
**modernBERT-base-multilingual-sentiment** is a multilingual sentiment classification model, part of
|
| 50 |
+
the [Multilingual-Sentiment](https://huggingface.co/collections/clapAI/multilingual-sentiment-677416a6b23e03f52cb6cc3f)
|
| 51 |
+
collection.
|
| 52 |
|
| 53 |
+
The model is fine-tuned from [FacebookAI/xlm-roberta-base](https://huggingface.co/FacebookAI/xlm-roberta-base) using the
|
| 54 |
+
multilingual sentiment
|
| 55 |
+
dataset [clapAI/MultiLingualSentiment](https://huggingface.co/datasets/clapAI/MultiLingualSentiment).
|
| 56 |
|
| 57 |
+
Model supports multilingual sentiment classification across 16+ languages, including English, Vietnamese, Chinese,
|
| 58 |
+
French, Spanish, Portuguese, German, Italian, Russian, Japanese, Korean, Arabic, and more.
|
| 59 |
|
| 60 |
+
## Evaluation & Performance
|
| 61 |
|
| 62 |
+
After fine-tuning, the best model is loaded and evaluated on the `test` dataset
|
| 63 |
+
from [clapAI/MultiLingualSentiment](https://huggingface.co/datasets/clapAI/MultiLingualSentiment)
|
| 64 |
|
| 65 |
+
|
| 66 |
+
| Model | Pretrained Model | Parameters | F1-score |
|
| 67 |
+
|:----------------------------------------------------------------------------------------------------------------:|:-----------------:|:----------:|:--------:|
|
| 68 |
+
| [modernBERT-base-multilingual-sentiment](https://huggingface.co/clapAI/modernBERT-base-multilingual-sentiment) | ModernBERT-base | 150M | 80.16 |
|
| 69 |
+
| [modernBERT-large-multilingual-sentiment](https://huggingface.co/clapAI/modernBERT-large-multilingual-sentiment) | ModernBERT-large | 396M | 81.4 |
|
| 70 |
+
| [roberta-base-multilingual-sentiment](https://huggingface.co/clapAI/roberta-base-multilingual-sentiment) | XLM-roberta-base | 278M | 81.8 |
|
| 71 |
+
| [roberta-large-multilingual-sentiment](https://huggingface.co/clapAI/roberta-large-multilingual-sentiment) | XLM-roberta-large | 560M | 82.6 |
|
| 72 |
+
|
| 73 |
+
## How to use
|
| 74 |
+
|
| 75 |
+
### Requirements
|
| 76 |
+
|
| 77 |
+
Since **transformers** only supports the **ModernBERT** architecture from version `4.48.0.dev0`, use the following
|
| 78 |
+
command to get the required version:
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
pip install "git+https://github.com/huggingface/transformers.git@6e0515e99c39444caae39472ee1b2fd76ece32f1" --upgrade
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
Install **FlashAttention** to accelerate inference performance
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
pip install flash-attn==2.7.2.post1
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
### Quick start
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
import torch
|
| 94 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 95 |
+
|
| 96 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 97 |
+
|
| 98 |
+
model_id = "clapAI/roberta-base-multilingual-sentiment"
|
| 99 |
+
# Load the tokenizer and model
|
| 100 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 101 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 102 |
+
|
| 103 |
+
model.to(device)
|
| 104 |
+
model.eval()
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
# Retrieve labels from the model's configuration
|
| 108 |
+
id2label = model.config.id2label
|
| 109 |
+
|
| 110 |
+
texts = [
|
| 111 |
+
# English
|
| 112 |
+
{
|
| 113 |
+
"text": "I absolutely love the new design of this app!",
|
| 114 |
+
"label": "positive"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"text": "The customer service was disappointing.",
|
| 118 |
+
"label": "negative"
|
| 119 |
+
},
|
| 120 |
+
# Arabic
|
| 121 |
+
{
|
| 122 |
+
"text": "هذا المنتج رائع للغاية!",
|
| 123 |
+
"label": "positive"
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"text": "الخدمة كانت سيئة للغاية.",
|
| 127 |
+
"label": "negative"
|
| 128 |
+
},
|
| 129 |
+
# German
|
| 130 |
+
{
|
| 131 |
+
"text": "Ich bin sehr zufrieden mit dem Kauf.",
|
| 132 |
+
"label": "positive"
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"text": "Die Lieferung war eine Katastrophe.",
|
| 136 |
+
"label": "negative"
|
| 137 |
+
},
|
| 138 |
+
# Spanish
|
| 139 |
+
{
|
| 140 |
+
"text": "Este es el mejor libro que he leído.",
|
| 141 |
+
"label": "positive"
|
| 142 |
+
},
|
| 143 |
+
{
|
| 144 |
+
"text": "El producto llegó roto y no funciona.",
|
| 145 |
+
"label": "negative"
|
| 146 |
+
},
|
| 147 |
+
# French
|
| 148 |
+
{
|
| 149 |
+
"text": "J'adore ce restaurant, la nourriture est délicieuse!",
|
| 150 |
+
"label": "positive"
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"text": "Le service était très lent et désagréable.",
|
| 154 |
+
"label": "negative"
|
| 155 |
+
},
|
| 156 |
+
# Indonesian
|
| 157 |
+
{
|
| 158 |
+
"text": "Saya sangat senang dengan pelayanan ini.",
|
| 159 |
+
"label": "positive"
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
"text": "Makanannya benar-benar tidak enak.",
|
| 163 |
+
"label": "negative"
|
| 164 |
+
},
|
| 165 |
+
# Japanese
|
| 166 |
+
{
|
| 167 |
+
"text": "この製品は本当に素晴らしいです!",
|
| 168 |
+
"label": "positive"
|
| 169 |
+
},
|
| 170 |
+
{
|
| 171 |
+
"text": "サービスがひどかったです。",
|
| 172 |
+
"label": "negative"
|
| 173 |
+
},
|
| 174 |
+
# Korean
|
| 175 |
+
{
|
| 176 |
+
"text": "이 제품을 정말 좋아해요!",
|
| 177 |
+
"label": "positive"
|
| 178 |
+
},
|
| 179 |
+
{
|
| 180 |
+
"text": "고객 서비스가 정말 실망스러웠어요.",
|
| 181 |
+
"label": "negative"
|
| 182 |
+
},
|
| 183 |
+
# Russian
|
| 184 |
+
{
|
| 185 |
+
"text": "Этот фильм просто потрясающий!",
|
| 186 |
+
"label": "positive"
|
| 187 |
+
},
|
| 188 |
+
{
|
| 189 |
+
"text": "Качество было ужасным.",
|
| 190 |
+
"label": "negative"
|
| 191 |
+
},
|
| 192 |
+
# Vietnamese
|
| 193 |
+
{
|
| 194 |
+
"text": "Tôi thực sự yêu thích sản phẩm này!",
|
| 195 |
+
"label": "positive"
|
| 196 |
+
},
|
| 197 |
+
{
|
| 198 |
+
"text": "Dịch vụ khách hàng thật tệ.",
|
| 199 |
+
"label": "negative"
|
| 200 |
+
},
|
| 201 |
+
# Chinese
|
| 202 |
+
{
|
| 203 |
+
"text": "我非常喜欢这款产品!",
|
| 204 |
+
"label": "positive"
|
| 205 |
+
},
|
| 206 |
+
{
|
| 207 |
+
"text": "质量真的很差。",
|
| 208 |
+
"label": "negative"
|
| 209 |
+
}
|
| 210 |
+
]
|
| 211 |
+
|
| 212 |
+
for item in texts:
|
| 213 |
+
text = item["text"]
|
| 214 |
+
label = item["label"]
|
| 215 |
+
|
| 216 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 217 |
+
|
| 218 |
+
# Perform inference in inference mode
|
| 219 |
+
with torch.inference_mode():
|
| 220 |
+
outputs = model(**inputs)
|
| 221 |
+
predictions = outputs.logits.argmax(dim=-1)
|
| 222 |
+
print(f"Text: {text} | Label: {label} | Prediction: {id2label[predictions.item()]}")
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
```
|
| 226 |
|
| 227 |
## Training procedure
|
| 228 |
|
| 229 |
### Training hyperparameters
|
| 230 |
|
| 231 |
The following hyperparameters were used during training:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
+
```yaml
|
| 234 |
+
learning_rate: 5e-05
|
| 235 |
+
train_batch_size: 512
|
| 236 |
+
eval_batch_size: 512
|
| 237 |
+
seed: 42
|
| 238 |
+
distributed_type: multi-GPU
|
| 239 |
+
num_devices: 2
|
| 240 |
+
gradient_accumulation_steps: 2
|
| 241 |
+
total_train_batch_size: 2048
|
| 242 |
+
total_eval_batch_size: 1024
|
| 243 |
+
optimizer:
|
| 244 |
+
type: adamw_torch_fused
|
| 245 |
+
betas: [ 0.9, 0.999 ]
|
| 246 |
+
epsilon: 1e-08
|
| 247 |
+
optimizer_args: "No additional optimizer arguments"
|
| 248 |
+
lr_scheduler:
|
| 249 |
+
type: cosine
|
| 250 |
+
warmup_ratio: 0.01
|
| 251 |
+
num_epochs: 5.0
|
| 252 |
+
mixed_precision_training: Native AMP
|
| 253 |
+
|
| 254 |
+
```
|
| 255 |
|
| 256 |
### Framework versions
|
| 257 |
|
| 258 |
+
```plaintex
|
| 259 |
+
transformers==4.48.0.dev0
|
| 260 |
+
torch==2.4.0+cu121
|
| 261 |
+
datasets==3.2.0
|
| 262 |
+
tokenizers==0.21.0
|
| 263 |
+
flash-attn==2.7.2.post1
|
| 264 |
+
```
|
| 265 |
+
|
| 266 |
+
## Citation
|
| 267 |
+
|
| 268 |
+
If you find our project helpful, please star our repo and cite our work. Thanks!
|
| 269 |
+
|
| 270 |
+
```bibtex
|
| 271 |
+
@misc{roberta-base-multilingual-sentiment,
|
| 272 |
+
title=roberta-base-multilingual-sentiment: A Multilingual Sentiment Classification Model},
|
| 273 |
+
author={clapAI},
|
| 274 |
+
howpublished={\url{https://huggingface.co/clapAI/roberta-base-multilingual-sentiment}},
|
| 275 |
+
year={2025},
|
| 276 |
+
}
|