WJL110 commited on
Commit
851dd83
1 Parent(s): 019fa9a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +26 -3
README.md CHANGED
@@ -19,7 +19,30 @@ license: mit
19
  ```python
20
  from transformers import pipeline
21
 
22
- classifier = pipeline("text-classification", model="WJL110/chinese-emotion-classifier")
23
- result = classifier("今天真是太开心了!")
24
- print(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ```
 
19
  ```python
20
  from transformers import pipeline
21
 
22
+ # 创建分类器
23
+ classifier = pipeline("text-classification", model="WJL110/emotion-classifier")
24
+
25
+ # 标签映射
26
+ label_map = {
27
+ "LABEL_0": "快乐",
28
+ "LABEL_1": "愤怒",
29
+ "LABEL_2": "悲伤"
30
+ }
31
+
32
+ # 测试文本
33
+ test_texts = [
34
+ "今天真是太开心了!",
35
+ "这件事让我很生气。",
36
+ "听到这个消息很难过。"
37
+ ]
38
+
39
+ print("=== 情感分析测试 ===")
40
+ for text in test_texts:
41
+ result = classifier(text)[0] # 获取第一个(也是唯一的)结果
42
+ emotion = label_map[result['label']]
43
+ confidence = result['score']
44
+
45
+ print(f"\n输入文本: {text}")
46
+ print(f"预测情感: {emotion}")
47
+ print(f"置信度: {confidence:.2f}")
48
  ```