dair-ai/emotion
Viewer • Updated • 437k • 34.8k • 443
How to use EnJiZ/FirstTimeUp with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="EnJiZ/FirstTimeUp") # Load model directly
from transformers import MultiLabelEmotionClassifier
model = MultiLabelEmotionClassifier.from_pretrained("EnJiZ/FirstTimeUp", dtype="auto")# Load model directly
from transformers import MultiLabelEmotionClassifier
model = MultiLabelEmotionClassifier.from_pretrained("EnJiZ/FirstTimeUp", dtype="auto")This model is fine-tuned for multilabel emotion classification using distilbert-base-uncased as the base model.
pip install torch transformers huggingface_hub
# Download the repository
from huggingface_hub import snapshot_download
import sys
import os
# Download model files
model_path = snapshot_download(repo_id="EnJiZ/FirstTimeUp")
# Add to path and import
sys.path.append(model_path)
from model import predict_emotions
# Predict emotions
text = "I am so happy and excited!"
emotions = predict_emotions(text, model_path)
print(emotions)
import torch
from transformers import AutoTokenizer
import sys
sys.path.append(model_path)
from model import MultiLabelEmotionClassifier, load_model
# Load model manually
model, config = load_model(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)
# Custom prediction with different threshold
def custom_predict(text, threshold=0.3):
encoding = tokenizer(
text,
truncation=True,
padding='max_length',
max_length=128,
return_tensors='pt'
)
model.eval()
with torch.no_grad():
logits = model(encoding['input_ids'], encoding['attention_mask'])
probabilities = torch.sigmoid(logits)
predictions = (probabilities > threshold).int()
emotion_labels = ['amusement', 'anger', 'annoyance', 'caring', 'confusion', 'disappointment', 'disgust', 'embarrassment', 'excitement', 'fear', 'gratitude', 'joy', 'love', 'sadness']
result = {emotion: {
'predicted': bool(pred),
'probability': float(prob)
} for emotion, pred, prob in zip(emotion_labels, predictions[0], probabilities[0])}
return result
# Example with probabilities
result = custom_predict("I feel great today!", threshold=0.3)
print(result)
config.json: Model configurationpytorch_model.bin: Model weightstokenizer.json, tokenizer_config.json: Tokenizer filesmodel.py: Custom model class and utility functionsREADME.md: This fileamusement, anger, annoyance, caring, confusion, disappointment, disgust, embarrassment, excitement, fear, gratitude, joy, love, sadness
This model is released under the Apache 2.0 license.
@misc{firsttimeup2024,
title={FirstTimeUp: Multilabel Emotion Classification Model},
author={EnJiZ},
year={2024},
url={https://huggingface.co/EnJiZ/FirstTimeUp}
}
For questions or issues, please open an issue in the repository.
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="EnJiZ/FirstTimeUp")