File size: 971 Bytes
019fa9a 851dd83 019fa9a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
---
language: zh
tags:
- chinese
- emotion
- classification
license: mit
---
# Chinese Emotion Classification Model
这是一个中文情感分类模型,可以将文本分类为三种情感:
- 快乐
- 愤怒
- 悲伤
## 使用方法
```python
from transformers import pipeline
# 创建分类器
classifier = pipeline("text-classification", model="WJL110/emotion-classifier")
# 标签映射
label_map = {
"LABEL_0": "快乐",
"LABEL_1": "愤怒",
"LABEL_2": "悲伤"
}
# 测试文本
test_texts = [
"今天真是太开心了!",
"这件事让我很生气。",
"听到这个消息很难过。"
]
print("=== 情感分析测试 ===")
for text in test_texts:
result = classifier(text)[0] # 获取第一个(也是唯一的)结果
emotion = label_map[result['label']]
confidence = result['score']
print(f"\n输入文本: {text}")
print(f"预测情感: {emotion}")
print(f"置信度: {confidence:.2f}")
```
|