added readme with example
Browse files
README.md
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Vent-roBERTa-emotion
|
2 |
+
|
3 |
+
This is a roBERTa pretrained on twitter and then trained for self-labeled emotion classification on the Vent dataset (see https://arxiv.org/abs/1901.04856). <br/>
|
4 |
+
The Vent dataset contains 33 million posts annotated with one emotion by the user themselves. <br/>
|
5 |
+
|
6 |
+
The model was trained to recognize 5 emotions ("Affection", "Anger", "Fear", "Happiness", "Sadness") on 7 million posts from the dataset. <br/>
|
7 |
+
|
8 |
+
Example of how to use the classifier on single texts. <br/>
|
9 |
+
|
10 |
+
````
|
11 |
+
from transformers import AutoModelForSequenceClassification
|
12 |
+
from transformers import AutoTokenizer
|
13 |
+
import numpy as np
|
14 |
+
from scipy.special import softmax
|
15 |
+
import torch
|
16 |
+
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained("lumalik/vent-roberta-emotion")
|
18 |
+
model = AutoModelForSequenceClassification.from_pretrained("lumalik/vent-roberta-emotion")
|
19 |
+
model.eval()
|
20 |
+
|
21 |
+
texts = ["I love her sooo much", "I hate you!"]
|
22 |
+
|
23 |
+
for text in texts:
|
24 |
+
encoded_text = tokenizer.encode_plus(text,
|
25 |
+
add_special_tokens=True,
|
26 |
+
max_length=128,
|
27 |
+
return_token_type_ids=True,
|
28 |
+
padding="max_length",
|
29 |
+
truncation=True,
|
30 |
+
return_attention_mask=True)
|
31 |
+
|
32 |
+
output = model(input_ids=torch.tensor(encoded_text['input_ids'], dtype=torch.long).unsqueeze(0),
|
33 |
+
token_type_ids=torch.tensor(encoded_text['token_type_ids'], dtype=torch.long).unsqueeze(0),
|
34 |
+
attention_mask=torch.tensor(encoded_text['attention_mask'], dtype=torch.long).unsqueeze(0))
|
35 |
+
|
36 |
+
output = softmax(output[0].detach().numpy(), axis=1)
|
37 |
+
|
38 |
+
print("======================")
|
39 |
+
print(text)
|
40 |
+
print("Affection: {}".format(output[0][0]))
|
41 |
+
print("Anger: {}".format(output[0][1]))
|
42 |
+
print("Fear: {}".format(output[0][2]))
|
43 |
+
print("Happiness: {}".format(output[0][3]))
|
44 |
+
print("Sadness: {}".format(output[0][4]))
|
45 |
+
````
|