🚀 (distil)BERTベースの感情分類モデル: 合成データの力を引き出す
このモデルは、合成データを用いた英文の感情分析に特化しており、ソーシャルメディア分析や顧客フィードバック分析など幅広い分野で利用できます。
🚀 クイックスタート
このセクションでは、このモデルの基本的な使い方を説明します。
モデルの詳細
プロパティ |
詳細 |
モデル名 |
tabularisai/robust-sentiment-analysis |
ベースモデル |
distilbert/distilbert-base-uncased |
タスク |
テキスト分類(感情分析) |
言語 |
英語 |
クラス数 |
5 (非常に否定的、否定的、中立的、肯定的、非常に肯定的) |
用途 |
ソーシャルメディア分析、顧客フィードバック分析、製品レビュー分類、ブランドモニタリング、市場調査、カスタマーサービス最適化、競合情報収集 |
モデルの説明
このモデルは、感情分析用にdistilbert/distilbert-base-uncased
をファインチューニングしたものです。合成データのみを使用してトレーニングされています。
トレーニングデータ
このモデルは合成データでファインチューニングされており、実世界のデータセットに見られる制限なしに、多様な感情表現に対するターゲットトレーニングが可能です。
トレーニング手順
- モデルは5エポックでファインチューニングされました。
- 検証データセットで、train_acc_off_by_one(1クラスの誤差を許容する精度)が約0.95を達成しました。
想定される用途
このモデルは感情分析タスクに設計されており、以下の用途に特に役立ちます。
- ソーシャルメディアモニタリング
- 顧客フィードバック分析
- 製品レビューの感情分類
- ブランドの感情追跡
💻 使用例
基本的な使用法
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "tabularisai/robust-sentiment-analysis"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
def predict_sentiment(text):
inputs = tokenizer(text.lower(), return_tensors="pt", truncation=True, padding=True, max_length=512)
with torch.no_grad():
outputs = model(**inputs)
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
predicted_class = torch.argmax(probabilities, dim=-1).item()
sentiment_map = {0: "Very Negative", 1: "Negative", 2: "Neutral", 3: "Positive", 4: "Very Positive"}
return sentiment_map[predicted_class]
texts = [
"I absolutely loved this movie! The acting was superb and the plot was engaging.",
"The service at this restaurant was terrible. I'll never go back.",
"The product works as expected. Nothing special, but it gets the job done.",
"I'm somewhat disappointed with my purchase. It's not as good as I hoped.",
"This book changed my life! I couldn't put it down and learned so much."
]
for text in texts:
sentiment = predict_sentiment(text)
print(f"Text: {text}")
print(f"Sentiment: {sentiment}\n")
高度な使用法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tabularis Sentiment Analysis</title>
</head>
<body>
<div id="output"></div>
<script type="module">
import { AutoTokenizer, AutoModel, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.6.0';
env.allowLocalModels = false;
env.useCDN = true;
const MODEL_NAME = 'tabularisai/robust-sentiment-analysis';
function softmax(arr) {
const max = Math.max(...arr);
const exp = arr.map(x => Math.exp(x - max));
const sum = exp.reduce((acc, val) => acc + val);
return exp.map(x => x / sum);
}
async function analyzeSentiment() {
try {
const tokenizer = await AutoTokenizer.from_pretrained(MODEL_NAME);
const model = await AutoModel.from_pretrained(MODEL_NAME);
const texts = [
"I absolutely loved this movie! The acting was superb and the plot was engaging.",
"The service at this restaurant was terrible. I'll never go back.",
"The product works as expected. Nothing special, but it gets the job done.",
"I'm somewhat disappointed with my purchase. It's not as good as I hoped.",
"This book changed my life! I couldn't put it down and learned so much."
];
const output = document.getElementById('output');
for (const text of texts) {
const inputs = await tokenizer(text, { return_tensors: 'pt' });
const result = await model(inputs);
console.log('Model output:', result);
if (result.output && result.output.data) {
const logitsArray = Array.from(result.output.data);
console.log('Logits array:', logitsArray);
const probabilities = softmax(logitsArray);
const predicted_class = probabilities.indexOf(Math.max(...probabilities));
const sentimentMap = {
0: "Very Negative",
1: "Negative",
2: "Neutral",
3: "Positive",
4: "Very Positive"
};
const sentiment = sentimentMap[predicted_class];
const score = probabilities[predicted_class];
output.innerHTML += `Text: "${text}"<br>`;
output.innerHTML += `Sentiment: ${sentiment}, Score: ${score.toFixed(4)}<br><br>`;
} else {
console.error('Unexpected model output structure:', result);
output.innerHTML += `Unable to process: "${text}"<br><br>`;
}
}
} catch (error) {
console.error('Error:', error);
document.getElementById('output').innerHTML = 'An error occurred. Please check the console for details.';
}
}
analyzeSentiment();
</script>
</body>
</html>
モデルの性能
このモデルは、様々な感情カテゴリにわたって強力な性能を示します。以下はいくつかの予測例です。
1. "I absolutely loved this movie! The acting was superb and the plot was engaging."
予測された感情: 非常に肯定的
2. "The service at this restaurant was terrible. I'll never go back."
予測された感情: 非常に否定的
3. "The product works as expected. Nothing special, but it gets the job done."
予測された感情: 中立的
4. "I'm somewhat disappointed with my purchase. It's not as good as I hoped."
予測された感情: 否定的
5. "This book changed my life! I couldn't put it down and learned so much."
予測された感情: 非常に肯定的
トレーニング手順
このモデルは、distilbert/distilbert-base-uncased
アーキテクチャを使用して合成データでファインチューニングされました。トレーニングプロセスには以下が含まれています。
- データセット: 幅広い感情表現をカバーするように設計された合成データ
- トレーニングフレームワーク: PyTorch Lightning
- エポック数: 5
- 性能指標: 検証データセットでtrain_acc_off_by_oneが約0.95を達成
倫理的な考慮事項
合成データを使用してバランスの取れた公正なモデルを作成するための努力がなされていますが、ユーザーはモデルにバイアスが残る可能性があることを認識する必要があります。特定のユースケースでモデルを十分にテストし、経時的にその性能を監視することが重要です。
引用
Will be included
お問い合わせ
質問や当社のモデルを使用したプライベートで信頼性の高いAPIについては、info@tabularis.ai
までお問い合わせください。
tabularis.ai
最新情報
- 2024/12: さらに優れたロバストな感情分析モデルをアップロードしました!エラー率が10%減少し、全体的な精度が向上しています!
ライセンス
このモデルは、Apache 2.0ライセンスの下で提供されています。