Johnson8187
commited on
Commit
•
fd161f6
1
Parent(s):
7bd2834
Update README.md
Browse files
README.md
CHANGED
@@ -7,4 +7,77 @@ base_model:
|
|
7 |
pipeline_tag: text-classification
|
8 |
tags:
|
9 |
- emotion
|
10 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
pipeline_tag: text-classification
|
8 |
tags:
|
9 |
- emotion
|
10 |
+
---
|
11 |
+
# chinese-text-emotion-classifier
|
12 |
+
|
13 |
+
## 📚 模型簡介
|
14 |
+
本模型基於 Hugging Face 提供的 [joeddav/xlm-roberta-large-xnli](https://huggingface.co/joeddav/xlm-roberta-large-xnli) 模型進行微調,專注於 **中文語句情感分析**。
|
15 |
+
通過微調,模型可以識別以下 8 種情緒標籤:
|
16 |
+
- **平淡語氣**
|
17 |
+
- **關切語調**
|
18 |
+
- **開心語調**
|
19 |
+
- **憤怒語調**
|
20 |
+
- **悲傷語調**
|
21 |
+
- **疑問語調**
|
22 |
+
- **驚奇語調**
|
23 |
+
- **厭惡語調**
|
24 |
+
|
25 |
+
該模型適用於多種場景,例如客服情緒監控、社交媒體分析以及用戶反饋分類。
|
26 |
+
|
27 |
+
---
|
28 |
+
|
29 |
+
## 🚀 快速開始
|
30 |
+
|
31 |
+
### 安裝依賴
|
32 |
+
請確保安裝了 Hugging Face 的 Transformers 庫和 PyTorch:
|
33 |
+
```bash
|
34 |
+
pip install transformers torch
|
35 |
+
```
|
36 |
+
|
37 |
+
### 加載模型
|
38 |
+
使用以下代碼加載模型和分詞器,並進行情感分類:
|
39 |
+
```python
|
40 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
41 |
+
import torch
|
42 |
+
|
43 |
+
# 加載模型和分詞器
|
44 |
+
model_name = "your_username/your_model_name"
|
45 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
46 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
47 |
+
|
48 |
+
# 標籤映射
|
49 |
+
label_mapping = {
|
50 |
+
0: "平淡語氣",
|
51 |
+
1: "關切語調",
|
52 |
+
2: "開心語調",
|
53 |
+
3: "憤怒語調",
|
54 |
+
4: "悲傷語調",
|
55 |
+
5: "疑問語調",
|
56 |
+
6: "驚奇語調",
|
57 |
+
7: "厭惡語調"
|
58 |
+
}
|
59 |
+
|
60 |
+
# 分析情感
|
61 |
+
def predict_emotion(text):
|
62 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
63 |
+
with torch.no_grad():
|
64 |
+
outputs = model(**inputs)
|
65 |
+
predicted_class = torch.argmax(outputs.logits).item()
|
66 |
+
return label_mapping[predicted_class]
|
67 |
+
|
68 |
+
# 測試
|
69 |
+
text = "雖然我努力了很久,但似乎總是做不到,我感到自己一無是處。"
|
70 |
+
emotion = predict_emotion(text)
|
71 |
+
print(f"文本: {text}")
|
72 |
+
print(f"預測情緒: {emotion}")
|
73 |
+
```
|
74 |
+
|
75 |
+
---
|
76 |
+
|
77 |
+
### 數據集
|
78 |
+
- 微調數據集來自4000個標註的繁體中文情感數據集,覆蓋了多種情緒類別,確保模型在情感分類上的泛化能力。
|
79 |
+
|
80 |
+
## 🌟 聯繫與反饋
|
81 |
+
如果您在使用該模型時有任何問題,請聯繫:
|
82 |
+
- 郵箱:`fable8043@gmail.com`
|
83 |
+
- Hugging Face 項目頁面:[chinese-text-emotion-classifier](https://huggingface.co/Johnson8187/chinese-text-emotion-classifier)
|