đ Chinese Text Emotion Classifier Small
A specialized model for Chinese text emotion analysis, fine - tuned from a pre - trained base model.
đ Quick Start
Install Dependencies
Ensure that you have installed Hugging Face's Transformers library and PyTorch:
pip install transformers torch
Load the Model
Use the following code to load the model and tokenizer, and perform emotion classification:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
label_mapping = {
0: "Neutral tone",
1: "Concerned tone",
2: "Happy tone",
3: "Angry tone",
4: "Sad tone",
5: "Questioning tone",
6: "Surprised tone",
7: "Disgusted tone"
}
def predict_emotion(text, model_path="Johnson8187/Chinese-Emotion-Small"):
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForSequenceClassification.from_pretrained(model_path).to(device)
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)
with torch.no_grad():
outputs = model(**inputs)
predicted_class = torch.argmax(outputs.logits).item()
predicted_emotion = label_mapping[predicted_class]
return predicted_emotion
if __name__ == "__main__":
test_texts = [
"Although I've tried hard for a long time, I always seem to fail. I feel useless.",
"What you said really confuses me. I have no idea how to react.",
"The world is so heartless. Why does it always give me such tests?",
"Sometimes, I just hope to have a little peace and not hear these boring topics anymore.",
"Every time I think of that past, my heart still aches. I really can't let it go.",
"I never thought there would be such a big change. Now I feel completely out of control.",
"I never expected you to do this. It surprises me beyond words.",
"I know I should be stronger, but sometimes, these emotions really drive me crazy."
]
for text in test_texts:
emotion = predict_emotion(text)
print(f"Text: {text}")
print(f"Predicted emotion: {emotion}\n")
⨠Features
This model is fine - tuned based on the [MoritzLaurer/mDeBERTa - v3 - base - mnli - xnli](https://huggingface.co/MoritzLaurer/mDeBERTa - v3 - base - mnli - xnli) model, specializing in Chinese text emotion analysis. Through fine - tuning, the model can identify the following 8 emotion labels:
- Neutral tone
- Concerned tone
- Happy tone
- Angry tone
- Sad tone
- Questioning tone
- Surprised tone
- Disgusted tone
The model is applicable to various scenarios, such as customer service emotion monitoring, social media analysis, and user feedback classification.
đĻ Dataset
- 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.
- [Johnson8187/Chinese_Multi - Emotion_Dialogue_Dataset](https://huggingface.co/datasets/Johnson8187/Chinese_Multi - Emotion_Dialogue_Dataset)
đ License
This project is under the MIT license.
đ Contact and Feedback
If you encounter any issues while using this model, please contact:
Email: fable8043@gmail.com
Hugging Face Project Page: chinese-Emotion-Small