许可证: mit
数据集:
- dair-ai/emotion
语言:
- en
库名称: transformers
示例输入:
- 文本: "我对结果非常满意!"
- 文本: "我对结果非常愤怒!"
标签:
- debarta
- debarta-v3-small
- 情绪分类器
Fast Emotion-X:基于微调DeBERTa V3 Small的情绪检测模型
本模型是基于microsoft/deberta-v3-small微调的情绪检测模型,使用dair-ai/emotion数据集训练而成。
概述
Fast Emotion-X是基于微软DeBERTa V3 Small模型微调的最先进情绪检测模型,能够准确将文本分类到六种情绪类别中。该模型充分利用DeBERTa的强大能力,并在全面的情绪数据集上进行微调,确保高准确性和可靠性。
模型详情
- 模型名称:
AnkitAI/deberta-v3-small-base-emotions-classifier
- 基础模型:
microsoft/deberta-v3-small
- 数据集: dair-ai/emotion
- 微调: 模型针对六种情绪类别(愤怒、厌恶、恐惧、快乐、悲伤和惊讶)进行了分类头的微调。
情绪标签
使用方法
您可以直接使用提供的Python包或Hugging Face的transformers
库来调用此模型。
安装
使用pip安装包:
pip install emotionclassifier
基础用法
以下是如何使用emotionclassifier
对单个文本进行分类的示例:
from emotionclassifier import EmotionClassifier
classifier = EmotionClassifier()
text = "我今天非常开心!"
result = classifier.predict(text)
print("情绪:", result['label'])
print("置信度:", result['confidence'])
批量处理
可以使用predict_batch
方法对多个文本进行分类:
texts = ["我今天非常开心!", "我很难过。"]
results = classifier.predict_batch(texts)
print("批量处理结果:", results)
可视化
可视化文本的情绪分布:
from emotionclassifier import plot_emotion_distribution
result = classifier.predict("我今天非常开心!")
plot_emotion_distribution(result['probabilities'], classifier.labels.values())
命令行界面(CLI)用法
也可以从命令行使用该包:
emotionclassifier --model deberta-v3-small --text "我今天非常开心!"
与DataFrame集成
对pandas DataFrame中的文本列进行分类:
import pandas as pd
from emotionclassifier import DataFrameEmotionClassifier
df = pd.DataFrame({
'text': ["我今天非常开心!", "我很难过。"]
})
classifier = DataFrameEmotionClassifier()
df = classifier.classify_dataframe(df, 'text')
print(df)
情绪趋势分析
分析并绘制情绪随时间变化的趋势:
from emotionclassifier import EmotionTrends
texts = ["我今天非常开心!", "我感觉还行。", "我非常难过。"]
trends = EmotionTrends()
emotions = trends.analyze_trends(texts)
trends.plot_trends(emotions)
微调
在自己的数据集上微调预训练模型:
from emotionclassifier.fine_tune import fine_tune_model
train_dataset = ...
val_dataset = ...
fine_tune_model(classifier.model, classifier.tokenizer, train_dataset, val_dataset, output_dir='fine_tuned_model')
使用transformers库
from transformers import AutoModelForSequenceClassification, AutoTokenizer
model_name = "AnkitAI/deberta-v3-small-base-emotions-classifier"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def predict_emotion(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)
outputs = model(**inputs)
logits = outputs.logits
predictions = logits.argmax(dim=1)
return predictions
text = "我对结果非常满意!"
emotion = predict_emotion(text)
print("检测到的情绪:", emotion)
训练
模型训练使用了以下参数:
- 学习率: 2e-5
- 批量大小: 4
- 权重衰减: 0.01
- 评估策略: 按周期
训练详情
- 评估损失: 0.0858
- 评估运行时间: 110070.6349秒
- 评估样本/秒: 78.495
- 评估步骤/秒: 2.453
- 训练损失: 0.1049
- 评估准确率: 94.6%
- 评估精确率: 94.8%
- 评估召回率: 94.5%
- 评估F1分数: 94.7%
模型卡片数据
参数 |
值 |
模型名称 |
microsoft/deberta-v3-small |
训练数据集 |
dair-ai/emotion |
训练周期数 |
20 |
学习率 |
2e-5 |
每个设备的训练批量大小 |
4 |
评估策略 |
按周期 |
最佳模型准确率 |
94.6% |
许可证
本模型采用MIT许可证。