🚀 clapAI/modernBERT-base-multilingual-sentiment
modernBERT-base-multilingual-sentiment は、Multilingual-Sentiment コレクションに含まれる多言語感情分類モデルです。このモデルは、多言語感情分析において、16 以上の言語に対応し、英語、ベトナム語、中国語、フランス語、スペイン語、ポルトガル語、ドイツ語、イタリア語、ロシア語、日本語、韓国語、アラビア語などの言語での感情分類をサポートします。
🚀 クイックスタート
必要条件
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/modernBERT-base-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 以上の言語に対応した感情分類が可能です。
- 高精度: 微調整により、高い F1 スコアを達成しています。
📦 インストール
インストールに必要なコマンドは以下の通りです。
pip install "git+https://github.com/huggingface/transformers.git@6e0515e99c39444caae39472ee1b2fd76ece32f1" --upgrade
pip install flash-attn==2.7.2.post1
📚 ドキュメント
モデルの概要
このモデルは answerdotai/ModernBERT-base をベースに、多言語感情データセット clapAI/MultiLingualSentiment を使用して微調整されています。
評価と性能
微調整後、最適なモデルがロードされ、clapAI/MultiLingualSentiment の test
データセットで評価されました。
トレーニング手順
トレーニングハイパーパラメータ
トレーニング時に使用されたハイパーパラメータは以下の通りです。
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
🔧 技術詳細
このモデルは、事前学習済みの ModernBERT-base
モデルを、多言語感情データセットで微調整することで構築されています。トレーニングには、多 GPU 環境を利用し、混合精度トレーニングを行っています。
📄 ライセンス
このプロジェクトは Apache-2.0 ライセンスの下で公開されています。
引用
もしこのプロジェクトが役に立った場合は、リポジトリをスターし、以下のように引用してください。
@misc{modernBERT-base-multilingual-sentiment,
title={modernBERT-base-multilingual-sentiment: A Multilingual Sentiment Classification Model},
author={clapAI},
howpublished={\url{https://huggingface.co/clapAI/modernBERT-base-multilingual-sentiment}},
year={2025},
}