Update README.md
Browse files
README.md
CHANGED
|
@@ -1,75 +1,152 @@
|
|
| 1 |
-
---
|
| 2 |
-
library_name: transformers
|
| 3 |
-
license: mit
|
| 4 |
-
base_model: jhu-clsp/mmBERT-small
|
| 5 |
-
tags:
|
| 6 |
-
-
|
| 7 |
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
|
| 12 |
-
-
|
| 13 |
-
|
| 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 |
-
# mmBERT-small-multilingual-sentiment
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
-
|
| 24 |
-
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
##
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
-
|
| 46 |
-
|
| 47 |
-
-
|
| 48 |
-
-
|
| 49 |
-
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
license: mit
|
| 4 |
+
base_model: jhu-clsp/mmBERT-small
|
| 5 |
+
tags:
|
| 6 |
+
- sentiment
|
| 7 |
+
- text-classification
|
| 8 |
+
- multilingual
|
| 9 |
+
- modernbert
|
| 10 |
+
- sentiment-analysis
|
| 11 |
+
- product-reviews
|
| 12 |
+
- place-reviews
|
| 13 |
+
- mmbert
|
| 14 |
+
metrics:
|
| 15 |
+
- f1
|
| 16 |
+
- precision
|
| 17 |
+
- recall
|
| 18 |
+
model-index:
|
| 19 |
+
- name: mmBERT-small-multilingual-sentiment
|
| 20 |
+
results: []
|
| 21 |
+
datasets:
|
| 22 |
+
- clapAI/MultiLingualSentiment
|
| 23 |
+
language:
|
| 24 |
+
- en
|
| 25 |
+
- zh
|
| 26 |
+
- vi
|
| 27 |
+
- ko
|
| 28 |
+
- ja
|
| 29 |
+
- ar
|
| 30 |
+
- de
|
| 31 |
+
- es
|
| 32 |
+
- fr
|
| 33 |
+
- hi
|
| 34 |
+
- id
|
| 35 |
+
- it
|
| 36 |
+
- ms
|
| 37 |
+
- pt
|
| 38 |
+
- ru
|
| 39 |
+
- tr
|
| 40 |
+
pipeline_tag: text-classification
|
| 41 |
+
---
|
| 42 |
|
| 43 |
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
| 44 |
should probably proofread and complete it, then remove this comment. -->
|
| 45 |
|
| 46 |
+
# clapAI/mmBERT-small-multilingual-sentiment
|
| 47 |
|
| 48 |
+
## Introduction
|
| 49 |
+
|
| 50 |
+
**mmBERT-small-multilingual-sentiment** is a multilingual sentiment classification model, part of
|
| 51 |
+
the [Multilingual-Sentiment](https://huggingface.co/collections/clapAI/multilingual-sentiment-677416a6b23e03f52cb6cc3f)
|
| 52 |
+
collection.
|
| 53 |
+
|
| 54 |
+
The model is fine-tuned from [jhu-clsp/mmBERT-small](https://huggingface.co/jhu-clsp/mmBERT-small) using the
|
| 55 |
+
multilingual sentiment
|
| 56 |
+
dataset [clapAI/MultiLingualSentiment](https://huggingface.co/datasets/clapAI/MultiLingualSentiment).
|
| 57 |
+
|
| 58 |
+
Model supports multilingual sentiment classification across 16+ languages, including English, Vietnamese, Chinese,
|
| 59 |
+
French, Spanish, Portuguese, German, Italian, Russian, Japanese, Korean, Arabic, and more.
|
| 60 |
+
|
| 61 |
+
## Key Highlights
|
| 62 |
+
> 📈 **Improved accuracy**: Achieves **F1 = 82.2**.
|
| 63 |
+
> 📜 **Long context support**: Handles sequences up to **8192 tokens**.
|
| 64 |
+
> 🪶 **Efficient size**: Only **140M parameters**, smaller than RoBERTa-base (278M) with better performance.
|
| 65 |
+
> ⚡ **FlashAttention-2 support**: Enables much faster inference on modern GPUs.
|
| 66 |
+
|
| 67 |
+
## Evaluation & Performance
|
| 68 |
+
|
| 69 |
+
Results on the test split
|
| 70 |
+
of [clapAI/MultiLingualSentiment](https://huggingface.co/datasets/clapAI/MultiLingualSentiment)
|
| 71 |
+
|
| 72 |
+
| Model | Pretrained Model | Parameters | Context-length | F1-score |
|
| 73 |
+
|:---------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------:|:----------:|----------------|:--------:|
|
| 74 |
+
| [clapAI/mmBERT-small-multilingual-sentiment](https://huggingface.co/clapAI/mmBERT-small-multilingual-sentiment) | [jhu-clsp/mmBERT-small](https://huggingface.co/jhu-clsp/mmBERT-small) | 140M | 8192 | **82.2** |
|
| 75 |
+
| [modernBERT-base-multilingual-sentiment](https://huggingface.co/clapAI/modernBERT-base-multilingual-sentiment) | [ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base) | 150M | 8192 | 80.16 |
|
| 76 |
+
| [roberta-base-multilingual-sentiment](https://huggingface.co/clapAI/roberta-base-multilingual-sentiment) | [XLM-roberta-base](https://huggingface.co/FacebookAI/xlm-roberta-base) | 278M | 512 | 81.8 |
|
| 77 |
+
|
| 78 |
+
## How to use
|
| 79 |
+
|
| 80 |
+
### Installation
|
| 81 |
+
|
| 82 |
+
```bash
|
| 83 |
+
pip install torch==2.8
|
| 84 |
+
pip install transformers==4.55.0
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
`Optional: accelerate inference with FlashAttention-2 (if supported by your GPU):`
|
| 88 |
+
|
| 89 |
+
```bash
|
| 90 |
+
pip install packaging
|
| 91 |
+
pip install ninja
|
| 92 |
+
MAX_JOBS=4 pip install flash-attn --no-build-isolation
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
### Example Usage
|
| 96 |
+
|
| 97 |
+
```python
|
| 98 |
+
import torch
|
| 99 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 100 |
+
|
| 101 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 102 |
+
|
| 103 |
+
model_id = "clapAI/mmBERT-small-multilingual-sentiment"
|
| 104 |
+
# Load the tokenizer and model
|
| 105 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 106 |
+
dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16
|
| 107 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 108 |
+
model_id,
|
| 109 |
+
torch_dtype=dtype,
|
| 110 |
+
# Uncomment if device supports FA2
|
| 111 |
+
# attn_implementation="flash_attention_2"
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
model.to(device)
|
| 115 |
+
model.eval()
|
| 116 |
+
|
| 117 |
+
# Retrieve labels from the model's configuration
|
| 118 |
+
id2label = model.config.id2label
|
| 119 |
+
|
| 120 |
+
texts = [
|
| 121 |
+
"I absolutely love the new design of this app!", # English
|
| 122 |
+
"الخدمة كانت سيئة للغاية.",
|
| 123 |
+
"Ich bin sehr zufrieden mit dem Kauf.", # German
|
| 124 |
+
"El producto llegó roto y no funciona.", # Spanish
|
| 125 |
+
"J'adore ce restaurant, la nourriture est délicieuse!", # French
|
| 126 |
+
"Makanannya benar-benar tidak enak.", # Indonesian
|
| 127 |
+
"この製品は本当に素晴らしいです!", # Japanese
|
| 128 |
+
"고객 서비스가 정말 실망스러웠어요.", # Korean
|
| 129 |
+
"Этот фильм просто потрясающий!", # Russian
|
| 130 |
+
"Tôi thực sự yêu thích sản phẩm này!", # Vietnamese
|
| 131 |
+
"质量真的很差。" # Chinese
|
| 132 |
+
]
|
| 133 |
+
|
| 134 |
+
for text in texts:
|
| 135 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 136 |
+
with torch.inference_mode():
|
| 137 |
+
outputs = model(**inputs)
|
| 138 |
+
prediction = id2label[outputs.logits.argmax(dim=-1).item()]
|
| 139 |
+
print(f"Text: {text} | Prediction: {prediction}")
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
## Citation
|
| 143 |
+
|
| 144 |
+
If you use this model, please consider citing:
|
| 145 |
+
|
| 146 |
+
```bibtex
|
| 147 |
+
@misc{clapAI_mmbert_small_multilingual_sentiment,
|
| 148 |
+
title={mmBERT-small-multilingual-sentiment: A Multilingual Sentiment Classification Model},
|
| 149 |
+
author={clapAI},
|
| 150 |
+
howpublished={\url{https://huggingface.co/clapAI/mmBERT-small-multilingual-sentiment}},
|
| 151 |
+
year={2025},
|
| 152 |
+
}
|