đ Chinese Text Emotion Classifier
This Chinese text emotion classifier is fine-tuned from a base model, featuring a smaller parameter size. It's an ideal choice for users who need faster inference speed, and its actual performance in tests is comparable to other models.
Model: Chinese-Emotion-Small
đ Quick Start
Install Dependencies
Make sure 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"):
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 unable to do it. I feel completely useless.",
"What you said really confused 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 stop hearing these boring topics.",
"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 surprised me beyond words.",
"I know I should be stronger, but sometimes, these emotions really make me on the verge of collapse."
]
for text in test_texts:
emotion = predict_emotion(text)
print(f"Text: {text}")
print(f"Predicted emotion: {emotion}\n")
⨠Features
- Specializes in Chinese text emotion analysis.
- Can identify 8 emotion labels: Neutral tone, Concerned tone, Happy tone, Angry tone, Sad tone, Questioning tone, Surprised tone, Disgusted tone.
- Applicable to various scenarios such as customer service emotion monitoring, social media analysis, and user feedback classification.
đ Documentation
Model Introduction
This model is fine-tuned based on the joeddav/xlm-roberta-large-xnli model, focusing on 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 suitable for various scenarios, including customer service emotion monitoring, social media analysis, and user feedback classification.
Dataset
đ License
This project is licensed under the MIT license.
đ Contact and Feedback
If you encounter any issues while using this model, please contact: