🚀 clapAI/modernBERT-large-multilingual-sentiment
roberta-large-multilingual-sentiment 是一個多語言情感分類模型,它能對多種語言的文本進行情感分析,可應用於產品評論、地點評論等場景,為跨語言的情感理解提供了有力支持。
🚀 快速開始
安裝依賴
由於 transformers 僅從 4.48.0.dev0
版本開始支持 ModernBERT 架構,你可以使用以下命令獲取所需版本:
pip install "git+https://github.com/huggingface/transformers.git@6e0515e99c39444caae39472ee1b2fd76ece32f1" --upgrade
安裝 FlashAttention 以加速推理性能:
pip install flash-attn==2.7.2.post1
代碼示例
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model_id = "clapAI/roberta-large-multilingual-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id, torch_dtype=torch.float16)
model.to(device)
model.eval()
id2label = model.config.id2label
texts = [
{
"text": "I absolutely love the new design of this app!",
"label": "positive"
},
{
"text": "The customer service was disappointing.",
"label": "negative"
},
{
"text": "هذا المنتج رائع للغاية!",
"label": "positive"
},
{
"text": "الخدمة كانت سيئة للغاية.",
"label": "negative"
},
{
"text": "Ich bin sehr zufrieden mit dem Kauf.",
"label": "positive"
},
{
"text": "Die Lieferung war eine Katastrophe.",
"label": "negative"
},
{
"text": "Este es el mejor libro que he leído.",
"label": "positive"
},
{
"text": "El producto llegó roto y no funciona.",
"label": "negative"
},
{
"text": "J'adore ce restaurant, la nourriture est délicieuse!",
"label": "positive"
},
{
"text": "Le service était très lent et désagréable.",
"label": "negative"
},
{
"text": "Saya sangat senang dengan pelayanan ini.",
"label": "positive"
},
{
"text": "Makanannya benar-benar tidak enak.",
"label": "negative"
},
{
"text": "この製品は本當に素晴らしいです!",
"label": "positive"
},
{
"text": "サービスがひどかったです。",
"label": "negative"
},
{
"text": "이 제품을 정말 좋아해요!",
"label": "positive"
},
{
"text": "고객 서비스가 정말 실망스러웠어요.",
"label": "negative"
},
{
"text": "Этот фильм просто потрясающий!",
"label": "positive"
},
{
"text": "Качество было ужасным.",
"label": "negative"
},
{
"text": "Tôi thực sự yêu thích sản phẩm này!",
"label": "positive"
},
{
"text": "Dịch vụ khách hàng thật tệ.",
"label": "negative"
},
{
"text": "我非常喜歡這款產品!",
"label": "positive"
},
{
"text": "質量真的很差。",
"label": "negative"
}
]
for item in texts:
text = item["text"]
label = item["label"]
inputs = tokenizer(text, return_tensors="pt").to(device)
with torch.inference_mode():
outputs = model(**inputs)
predictions = outputs.logits.argmax(dim=-1)
print(f"Text: {text} | Label: {label} | Prediction: {id2label[predictions.item()]}")
✨ 主要特性
- 多語言支持:該模型支持包括英語、越南語、中文、法語、西班牙語、葡萄牙語、德語、意大利語、俄語、日語、韓語、阿拉伯語等在內的 16 種以上語言的情感分類。
- 微調優化:模型基於 [FacebookAI/xlm - roberta - base](https://huggingface.co/FacebookAI/xlm - roberta - base) 進行微調,使用了多語言情感數據集 clapAI/MultiLingualSentiment,提升了情感分類的準確性。
📚 詳細文檔
評估與性能
微調後,加載最佳模型並在 clapAI/MultiLingualSentiment 的 test
數據集上進行評估。
模型 |
預訓練模型 |
參數數量 |
F1 分數 |
[modernBERT - base - multilingual - sentiment](https://huggingface.co/clapAI/modernBERT - base - multilingual - sentiment) |
ModernBERT - base |
150M |
80.16 |
[modernBERT - large - multilingual - sentiment](https://huggingface.co/clapAI/modernBERT - large - multilingual - sentiment) |
ModernBERT - large |
396M |
81.4 |
[roberta - base - multilingual - sentiment](https://huggingface.co/clapAI/roberta - base - multilingual - sentiment) |
XLM - roberta - base |
278M |
81.8 |
[roberta - large - multilingual - sentiment](https://huggingface.co/clapAI/roberta - large - multilingual - sentiment) |
XLM - roberta - large |
560M |
82.6 |
訓練過程
訓練超參數
訓練過程中使用了以下超參數:
learning_rate: 5e-05
train_batch_size: 512
eval_batch_size: 512
seed: 42
distributed_type: multi - GPU
num_devices: 2
gradient_accumulation_steps: 2
total_train_batch_size: 2048
total_eval_batch_size: 1024
optimizer:
type: adamw_torch_fused
betas: [ 0.9, 0.999 ]
epsilon: 1e-08
optimizer_args: "No additional optimizer arguments"
lr_scheduler:
type: cosine
warmup_ratio: 0.01
num_epochs: 5.0
mixed_precision_training: Native AMP
框架版本
transformers==4.48.0.dev0
torch==2.4.0+cu121
datasets==3.2.0
tokenizers==0.21.0
flash - attn==2.7.2.post1
🔧 技術細節
模型信息
📄 許可證
本項目採用 Apache - 2.0 許可證。
📖 引用
如果您覺得我們的項目有幫助,請給我們的倉庫點個星並引用我們的工作,謝謝!
@misc{roberta-large-multilingual-sentiment,
title=roberta-large-multilingual-sentiment: A Multilingual Sentiment Classification Model},
author={clapAI},
howpublished={\url{https://huggingface.co/clapAI/roberta-large-multilingual-sentiment}},
year={2025},
}