Commit
·
769cc58
1
Parent(s):
6e0b0c7
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
| 1 |
---
|
| 2 |
license: openrail
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: openrail
|
| 3 |
---
|
| 4 |
+
import torch
|
| 5 |
+
from transformers import AutoTokenizer, MobileBertForSequenceClassification
|
| 6 |
+
|
| 7 |
+
# Load the saved model
|
| 8 |
+
model_name = 'harshith20/Emotion_predictor'
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
+
model = MobileBertForSequenceClassification.from_pretrained(model_name)
|
| 11 |
+
|
| 12 |
+
# Tokenize input text
|
| 13 |
+
input_text = "I am feeling happy today"
|
| 14 |
+
encoded_text = tokenizer.encode_plus(
|
| 15 |
+
input_text,
|
| 16 |
+
max_length=128,
|
| 17 |
+
padding='max_length',
|
| 18 |
+
truncation=True,
|
| 19 |
+
return_attention_mask=True,
|
| 20 |
+
return_tensors='pt'
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Predict emotion
|
| 24 |
+
with torch.no_grad():
|
| 25 |
+
logits = model(**encoded_text)[0]
|
| 26 |
+
predicted_emotion = torch.argmax(logits).item()
|
| 27 |
+
emotion_labels = ['anger', 'fear', 'joy', 'love', 'sadness', 'surprise']
|
| 28 |
+
predicted_emotion_label = emotion_labels[predicted_emotion]
|
| 29 |
+
|
| 30 |
+
print(f"Input text: {input_text}")
|
| 31 |
+
print(f"Predicted emotion: {predicted_emotion_label}")
|