🚀 快速情感分类器(Fast Emotion-X):基于微调DeBERTa V3 Small的情感检测模型
快速情感分类器(Fast Emotion-X)是一个基于微调DeBERTa V3 Small的情感检测模型,它利用dair-ai/emotion数据集,能够准确地将文本分类到六种情感类别中,为情感分析提供了高效且准确的解决方案。
🚀 快速开始
快速情感分类器(Fast Emotion-X)是一款基于微软DeBERTa V3 Small模型微调的先进情感检测模型。它旨在将文本准确分类到六种情感类别中。借助DeBERTa强大的能力,该模型在全面的情感数据集上进行了微调,确保了高准确性和可靠性。
✨ 主要特性
- 基于微调的DeBERTa V3 Small模型,具有较高的准确性和可靠性。
- 能够将文本准确分类到六种情感类别:愤怒、厌恶、恐惧、喜悦、悲伤和惊讶。
- 提供多种使用方式,包括Python包、Hugging Face
transformers
库、命令行界面(CLI)等。
- 支持单文本分类、批量处理、数据框集成以及情感趋势分析等功能。
📦 安装指南
使用pip安装包:
pip install emotionclassifier
💻 使用示例
基础用法
以下是如何使用 emotionclassifier
对单个文本进行分类的示例:
from emotionclassifier import EmotionClassifier
classifier = EmotionClassifier()
text = "I am very happy today!"
result = classifier.predict(text)
print("Emotion:", result['label'])
print("Confidence:", result['confidence'])
高级用法 - 批量处理
你可以使用 predict_batch
方法一次性对多个文本进行分类:
texts = ["I am very happy today!", "I am so sad."]
results = classifier.predict_batch(texts)
print("Batch processing results:", results)
高级用法 - 可视化
要可视化文本的情感分布:
from emotionclassifier import plot_emotion_distribution
result = classifier.predict("I am very happy today!")
plot_emotion_distribution(result['probabilities'], classifier.labels.values())
高级用法 - 命令行界面(CLI)使用
你也可以从命令行使用该包:
emotionclassifier --model deberta-v3-small --text "I am very happy today!"
高级用法 - 数据框集成
与pandas数据框集成以对文本列进行分类:
import pandas as pd
from emotionclassifier import DataFrameEmotionClassifier
df = pd.DataFrame({
'text': ["I am very happy today!", "I am so sad."]
})
classifier = DataFrameEmotionClassifier()
df = classifier.classify_dataframe(df, 'text')
print(df)
高级用法 - 情感趋势分析
分析并绘制随时间变化的情感趋势:
from emotionclassifier import EmotionTrends
texts = ["I am very happy today!", "I am feeling okay.", "I am very sad."]
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 = "I'm so happy with the results!"
emotion = predict_emotion(text)
print("Detected Emotion:", emotion)
📚 详细文档
模型详情
- 模型名称:
AnkitAI/deberta-v3-small-base-emotions-classifier
- 基础模型:
microsoft/deberta-v3-small
- 数据集:dair-ai/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许可证。