Johnson8187
commited on
Commit
•
1e79b0e
1
Parent(s):
4277b3e
Update README.md
Browse files
README.md
CHANGED
@@ -10,6 +10,24 @@ tags:
|
|
10 |
---
|
11 |
# chinese-text-emotion-classifier
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
## 📚 模型簡介
|
14 |
本模型基於[joeddav/xlm-roberta-large-xnli](https://huggingface.co/joeddav/xlm-roberta-large-xnli) 模型進行微調,專注於 **中文語句情感分析**。
|
15 |
通過微調,模型可以識別以下 8 種情緒標籤:
|
@@ -25,7 +43,74 @@ tags:
|
|
25 |
該模型適用於多種場景,例如客服情緒監控、社交媒體分析以及用戶反饋分類。
|
26 |
|
27 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
## 🚀 快速開始
|
30 |
|
31 |
### 安裝依賴
|
@@ -95,10 +180,23 @@ if __name__ == "__main__":
|
|
95 |
|
96 |
---
|
97 |
|
|
|
|
|
|
|
|
|
|
|
98 |
### 數據集
|
99 |
- 微調數據集來自4000個標註的繁體中文情感數據集,覆蓋了多種情緒類別,確保模型在情感分類上的泛化能力。
|
100 |
- 數據集正在準備公開
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
## 🌟 聯繫與反饋
|
103 |
如果您在使用該模型時有任何問題,請聯繫:
|
104 |
- 郵箱:`fable8043@gmail.com`
|
|
|
10 |
---
|
11 |
# chinese-text-emotion-classifier
|
12 |
|
13 |
+
## 📚 Model Introduction
|
14 |
+
|
15 |
+
This model is fine-tuned based on the [joeddav/xlm-roberta-large-xnli](https://huggingface.co/joeddav/xlm-roberta-large-xnli) model, specializing in **Chinese text emotion analysis**.
|
16 |
+
Through fine-tuning, the model can identify the following 8 emotion labels:
|
17 |
+
- **Neutral tone**
|
18 |
+
- **Concerned tone**
|
19 |
+
- **Happy tone**
|
20 |
+
- **Angry tone**
|
21 |
+
- **Sad tone**
|
22 |
+
- **Questioning tone**
|
23 |
+
- **Surprised tone**
|
24 |
+
- **Disgusted tone**
|
25 |
+
|
26 |
+
The model is applicable to various scenarios, such as customer service emotion monitoring, social media analysis, and user feedback classification.
|
27 |
+
|
28 |
+
---
|
29 |
+
# chinese-text-emotion-classifier
|
30 |
+
|
31 |
## 📚 模型簡介
|
32 |
本模型基於[joeddav/xlm-roberta-large-xnli](https://huggingface.co/joeddav/xlm-roberta-large-xnli) 模型進行微調,專注於 **中文語句情感分析**。
|
33 |
通過微調,模型可以識別以下 8 種情緒標籤:
|
|
|
43 |
該模型適用於多種場景,例如客服情緒監控、社交媒體分析以及用戶反饋分類。
|
44 |
|
45 |
---
|
46 |
+
## 🚀 Quick Start
|
47 |
+
|
48 |
+
### Install Dependencies
|
49 |
+
Ensure that you have installed Hugging Face's Transformers library and PyTorch:
|
50 |
+
```bash
|
51 |
+
pip install transformers torch
|
52 |
+
```
|
53 |
+
|
54 |
+
###Load the Model
|
55 |
+
Use the following code to load the model and tokenizer, and perform emotion classification:
|
56 |
+
```python
|
57 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
58 |
+
import torch
|
59 |
+
|
60 |
+
# 添加設備設定
|
61 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
62 |
+
|
63 |
+
# 標籤映射字典
|
64 |
+
label_mapping = {
|
65 |
+
0: "平淡語氣",
|
66 |
+
1: "關切語調",
|
67 |
+
2: "開心語調",
|
68 |
+
3: "憤怒語調",
|
69 |
+
4: "悲傷語調",
|
70 |
+
5: "疑問語調",
|
71 |
+
6: "驚奇語調",
|
72 |
+
7: "厭惡語調"
|
73 |
+
}
|
74 |
+
|
75 |
+
def predict_emotion(text, model_path="Johnson8187/chinese-text-emotion-classifier"):
|
76 |
+
# 載入模型和分詞器
|
77 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
78 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path).to(device) # 移動模型到設備
|
79 |
+
|
80 |
+
# 將文本轉換為模型輸入格式
|
81 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device) # 移動輸入到設備
|
82 |
+
|
83 |
+
# 進行預測
|
84 |
+
with torch.no_grad():
|
85 |
+
outputs = model(**inputs)
|
86 |
+
|
87 |
+
# 取得預測結果
|
88 |
+
predicted_class = torch.argmax(outputs.logits).item()
|
89 |
+
predicted_emotion = label_mapping[predicted_class]
|
90 |
+
|
91 |
+
return predicted_emotion
|
92 |
|
93 |
+
if __name__ == "__main__":
|
94 |
+
# 使用範例
|
95 |
+
test_texts = [
|
96 |
+
"雖然我努力了很久,但似乎總是做不到,我感到自己一無是處。",
|
97 |
+
"你說的那些話真的讓我很困惑,完全不知道該怎麼反應。",
|
98 |
+
"這世界真的是無情,為什麼每次都要給我這樣的考驗?",
|
99 |
+
"有時候,我只希望能有一點安靜,不要再聽到這些無聊的話題。",
|
100 |
+
"每次想起那段過去,我的心還是會痛,真的無法釋懷。",
|
101 |
+
"我從來沒有想過會有這麼大的改變,現在我覺得自己完全失控了。",
|
102 |
+
"我完全沒想到你會這麼做,這讓我驚訝到無法言喻。",
|
103 |
+
"我知道我應該更堅強,但有些時候,這種情緒真的讓我快要崩潰了。"
|
104 |
+
]
|
105 |
+
|
106 |
+
for text in test_texts:
|
107 |
+
emotion = predict_emotion(text)
|
108 |
+
print(f"文本: {text}")
|
109 |
+
print(f"預測情緒: {emotion}\n")
|
110 |
+
|
111 |
+
```
|
112 |
+
|
113 |
+
---
|
114 |
## 🚀 快速開始
|
115 |
|
116 |
### 安裝依賴
|
|
|
180 |
|
181 |
---
|
182 |
|
183 |
+
### Dataset
|
184 |
+
- The fine-tuning dataset consists of 4,000 annotated Traditional Chinese emotion samples, covering various emotion categories to ensure the model's generalization capability in emotion classification.
|
185 |
+
- The dataset is being prepared for public release.
|
186 |
+
|
187 |
+
|
188 |
### 數據集
|
189 |
- 微調數據集來自4000個標註的繁體中文情感數據集,覆蓋了多種情緒類別,確保模型在情感分類上的泛化能力。
|
190 |
- 數據集正在準備公開
|
191 |
|
192 |
+
---
|
193 |
+
|
194 |
+
🌟 Contact and Feedback
|
195 |
+
If you encounter any issues while using this model, please contact:
|
196 |
+
|
197 |
+
Email: fable8043@gmail.com
|
198 |
+
Hugging Face Project Page: chinese-text-emotion-classifier
|
199 |
+
|
200 |
## 🌟 聯繫與反饋
|
201 |
如果您在使用該模型時有任何問題,請聯繫:
|
202 |
- 郵箱:`fable8043@gmail.com`
|