🚀 Albert-base-v2-emotion
该项目基于Albert-base-v2模型,在情感数据集上进行微调,用于文本情感分类任务。它能有效识别文本中的情感类别,如悲伤、喜悦、爱等,为自然语言处理中的情感分析提供了有力支持。
🚀 快速开始
你可以使用以下代码快速调用该模型进行文本情感分类:
from transformers import pipeline
classifier = pipeline("text-classification",model='bhadresh-savani/albert-base-v2-emotion', return_all_scores=True)
prediction = classifier("I love using transformers. The best part is wide range of support and its easy to use", )
print(prediction)
"""
Output:
[[
{'label': 'sadness', 'score': 0.010403595864772797},
{'label': 'joy', 'score': 0.8902180790901184},
{'label': 'love', 'score': 0.042532723397016525},
{'label': 'anger', 'score': 0.041297927498817444},
{'label': 'fear', 'score': 0.011772023513913155},
{'label': 'surprise', 'score': 0.0037756056990474463}
]]
"""
✨ 主要特性
- 轻量级架构:基于Albert(A Lite BERT)架构,相较于传统的BERT架构,参数显著减少。
- 多情感分类:能够识别多种情感类别,如悲伤、喜悦、爱、愤怒、恐惧和惊讶等。
📦 安装指南
文档未提及具体安装步骤,可参考Hugging Face的通用安装指南来安装所需依赖。
💻 使用示例
基础用法
from transformers import pipeline
classifier = pipeline("text-classification",model='bhadresh-savani/albert-base-v2-emotion', return_all_scores=True)
prediction = classifier("I love using transformers. The best part is wide range of support and its easy to use", )
print(prediction)
"""
Output:
[[
{'label': 'sadness', 'score': 0.010403595864772797},
{'label': 'joy', 'score': 0.8902180790901184},
{'label': 'love', 'score': 0.042532723397016525},
{'label': 'anger', 'score': 0.041297927498817444},
{'label': 'fear', 'score': 0.011772023513913155},
{'label': 'surprise', 'score': 0.0037756056990474463}
]]
"""
📚 详细文档
模型描述
Albert 是一种轻量级的BERT架构,相较于传统的BERT架构,其参数显著减少。
Albert-base-v2 在情感数据集上使用HuggingFace Trainer进行了微调,使用的超参数如下:
学习率 2e-5,
批量大小 64,
训练轮数 num_train_epochs = 8
模型性能比较
在来自Twitter的情感数据集上,该模型与其他模型的性能对比如下:
数据集
使用的数据集为 Twitter-Sentiment-Analysis。
训练过程
训练过程可参考 Colab Notebook。
评估结果
{
"test_accuracy": 0.936,
"test_f1": 0.9365658988006296,
"test_loss": 0.15278364717960358,
"test_runtime": 10.9413,
"test_samples_per_second": 182.794,
"test_steps_per_second": 2.925
}
参考资料
📄 许可证
本项目采用 Apache-2.0 许可证。