Update README.md
Browse files
README.md
CHANGED
@@ -39,6 +39,14 @@ model_name = "codewithdark/bert-Gomotions"
|
|
39 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
40 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Example text
|
43 |
text = "I'm so happy today!"
|
44 |
inputs = tokenizer(text, return_tensors="pt")
|
@@ -46,9 +54,27 @@ inputs = tokenizer(text, return_tensors="pt")
|
|
46 |
# Predict
|
47 |
with torch.no_grad():
|
48 |
outputs = model(**inputs)
|
49 |
-
probs = torch.sigmoid(outputs.logits)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
```
|
53 |
|
54 |
## 🏋️♂️ Training Details
|
@@ -64,7 +90,7 @@ print(probs) # Multi-label predictions
|
|
64 |
```python
|
65 |
from transformers import pipeline
|
66 |
|
67 |
-
classifier = pipeline("text-classification", model="
|
68 |
classifier("I'm so excited about the trip!")
|
69 |
```
|
70 |
|
|
|
39 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
40 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
41 |
|
42 |
+
# Emotion labels (adjust based on your dataset)
|
43 |
+
emotion_labels = [
|
44 |
+
"Admiration", "Amusement", "Anger", "Annoyance", "Approval", "Caring", "Confusion",
|
45 |
+
"Curiosity", "Desire", "Disappointment", "Disapproval", "Disgust", "Embarrassment",
|
46 |
+
"Excitement", "Fear", "Gratitude", "Grief", "Joy", "Love", "Nervousness", "Optimism",
|
47 |
+
"Pride", "Realization", "Relief", "Remorse", "Sadness", "Surprise", "Neutral"
|
48 |
+
]
|
49 |
+
|
50 |
# Example text
|
51 |
text = "I'm so happy today!"
|
52 |
inputs = tokenizer(text, return_tensors="pt")
|
|
|
54 |
# Predict
|
55 |
with torch.no_grad():
|
56 |
outputs = model(**inputs)
|
57 |
+
probs = torch.sigmoid(outputs.logits).squeeze(0) # Convert logits to probabilities
|
58 |
+
|
59 |
+
# Get top 5 predictions
|
60 |
+
top5_indices = torch.argsort(probs, descending=True)[:5] # Get indices of top 5 labels
|
61 |
+
top5_labels = [emotion_labels[i] for i in top5_indices]
|
62 |
+
top5_probs = [probs[i].item() for i in top5_indices]
|
63 |
+
|
64 |
+
# Print results
|
65 |
+
print("Top 5 Predicted Emotions:")
|
66 |
+
for label, prob in zip(top5_labels, top5_probs):
|
67 |
+
print(f"{label}: {prob:.4f}")
|
68 |
|
69 |
+
'''
|
70 |
+
output:
|
71 |
+
Top 5 Predicted Emotions:
|
72 |
+
Joy: 0.9478
|
73 |
+
Love: 0.7854
|
74 |
+
Optimism: 0.6342
|
75 |
+
Admiration: 0.5678
|
76 |
+
Excitement: 0.5231
|
77 |
+
'''
|
78 |
```
|
79 |
|
80 |
## 🏋️♂️ Training Details
|
|
|
90 |
```python
|
91 |
from transformers import pipeline
|
92 |
|
93 |
+
classifier = pipeline("text-classification", model="codewithdark/bert-Gomotions", top_k=None)
|
94 |
classifier("I'm so excited about the trip!")
|
95 |
```
|
96 |
|