cardiffnlp
commited on
Commit
β’
e3dd608
1
Parent(s):
d2db038
Adding tweeteval classifier
Browse files- .ipynb_checkpoints/README-checkpoint.md +87 -0
- README.md +87 -0
- config.json +35 -0
- merges.txt +0 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tf_model.h5 +3 -0
- vocab.json +0 -0
.ipynb_checkpoints/README-checkpoint.md
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Twitter-roBERTa-base
|
2 |
+
|
3 |
+
This is a roBERTa-base model trained on ~58M tweets and finetuned for the emotion prediction task at Semeval 2018.
|
4 |
+
For full description: [_TweetEval_ benchmark (Findings of EMNLP 2020)](https://arxiv.org/pdf/2010.12421.pdf).
|
5 |
+
To evaluate this and other models on Twitter-specific data, please refer to the [Tweeteval official repository](https://github.com/cardiffnlp/tweeteval).
|
6 |
+
|
7 |
+
## Example of classification
|
8 |
+
|
9 |
+
```python
|
10 |
+
from transformers import AutoModelForSequenceClassification
|
11 |
+
from transformers import TFAutoModelForSequenceClassification
|
12 |
+
from transformers import AutoTokenizer
|
13 |
+
import numpy as np
|
14 |
+
from scipy.special import softmax
|
15 |
+
import csv
|
16 |
+
import urllib.request
|
17 |
+
|
18 |
+
# Tasks:
|
19 |
+
# emoji, emotion, hate, irony, offensive, sentiment
|
20 |
+
# stance/abortion, stance/atheism, stance/climate, stance/feminist, stance/hillary
|
21 |
+
|
22 |
+
task='emotion'
|
23 |
+
MODEL = f"cardiffnlp/twitter-roberta-base-{task}"
|
24 |
+
|
25 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
26 |
+
|
27 |
+
# download label mapping
|
28 |
+
labels=[]
|
29 |
+
mapping_link = f"https://raw.githubusercontent.com/cardiffnlp/tweeteval/main/datasets/{task}/mapping.txt"
|
30 |
+
with urllib.request.urlopen(mapping_link) as f:
|
31 |
+
html = f.read().decode('utf-8').split("\n")
|
32 |
+
spamreader = csv.reader(html[:-1], delimiter='\t')
|
33 |
+
labels = [row[1] for row in spamreader]
|
34 |
+
|
35 |
+
# PT
|
36 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
37 |
+
model.save_pretrained(MODEL)
|
38 |
+
|
39 |
+
text = "Good night π"
|
40 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
41 |
+
output = model(**encoded_input)
|
42 |
+
scores = output[0][0].detach().numpy()
|
43 |
+
scores = softmax(scores)
|
44 |
+
|
45 |
+
# # TF
|
46 |
+
# model = TFAutoModelForSequenceClassification.from_pretrained(MODEL)
|
47 |
+
# model.save_pretrained(MODEL)
|
48 |
+
|
49 |
+
# text = "Good night π"
|
50 |
+
# encoded_input = tokenizer(text, return_tensors='tf')
|
51 |
+
# output = model(encoded_input)
|
52 |
+
# scores = output[0][0].numpy()
|
53 |
+
# scores = softmax(scores)
|
54 |
+
|
55 |
+
ranking = np.argsort(scores)
|
56 |
+
ranking = ranking[::-1]
|
57 |
+
for i in range(scores.shape[0]):
|
58 |
+
l = labels[ranking[i]]
|
59 |
+
s = scores[ranking[i]]
|
60 |
+
print(f"{i+1}) {l} {np.round(float(s), 4)}")
|
61 |
+
|
62 |
+
```
|
63 |
+
|
64 |
+
Output:
|
65 |
+
|
66 |
+
```
|
67 |
+
1) π 0.2637
|
68 |
+
2) β€οΈ 0.1952
|
69 |
+
3) π 0.1171
|
70 |
+
4) β¨ 0.0927
|
71 |
+
5) π 0.0756
|
72 |
+
6) π 0.046
|
73 |
+
7) π 0.0444
|
74 |
+
8) π 0.0272
|
75 |
+
9) π 0.0228
|
76 |
+
10) π 0.0198
|
77 |
+
11) π 0.0166
|
78 |
+
12) π 0.0132
|
79 |
+
13) π 0.0131
|
80 |
+
14) β 0.0112
|
81 |
+
15) π 0.009
|
82 |
+
16) π― 0.009
|
83 |
+
17) π₯ 0.008
|
84 |
+
18) π· 0.0057
|
85 |
+
19) πΊπΈ 0.005
|
86 |
+
20) πΈ 0.0048
|
87 |
+
```
|
README.md
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Twitter-roBERTa-base
|
2 |
+
|
3 |
+
This is a roBERTa-base model trained on ~58M tweets and finetuned for the emotion prediction task at Semeval 2018.
|
4 |
+
For full description: [_TweetEval_ benchmark (Findings of EMNLP 2020)](https://arxiv.org/pdf/2010.12421.pdf).
|
5 |
+
To evaluate this and other models on Twitter-specific data, please refer to the [Tweeteval official repository](https://github.com/cardiffnlp/tweeteval).
|
6 |
+
|
7 |
+
## Example of classification
|
8 |
+
|
9 |
+
```python
|
10 |
+
from transformers import AutoModelForSequenceClassification
|
11 |
+
from transformers import TFAutoModelForSequenceClassification
|
12 |
+
from transformers import AutoTokenizer
|
13 |
+
import numpy as np
|
14 |
+
from scipy.special import softmax
|
15 |
+
import csv
|
16 |
+
import urllib.request
|
17 |
+
|
18 |
+
# Tasks:
|
19 |
+
# emoji, emotion, hate, irony, offensive, sentiment
|
20 |
+
# stance/abortion, stance/atheism, stance/climate, stance/feminist, stance/hillary
|
21 |
+
|
22 |
+
task='emotion'
|
23 |
+
MODEL = f"cardiffnlp/twitter-roberta-base-{task}"
|
24 |
+
|
25 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
26 |
+
|
27 |
+
# download label mapping
|
28 |
+
labels=[]
|
29 |
+
mapping_link = f"https://raw.githubusercontent.com/cardiffnlp/tweeteval/main/datasets/{task}/mapping.txt"
|
30 |
+
with urllib.request.urlopen(mapping_link) as f:
|
31 |
+
html = f.read().decode('utf-8').split("\n")
|
32 |
+
spamreader = csv.reader(html[:-1], delimiter='\t')
|
33 |
+
labels = [row[1] for row in spamreader]
|
34 |
+
|
35 |
+
# PT
|
36 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
37 |
+
model.save_pretrained(MODEL)
|
38 |
+
|
39 |
+
text = "Good night π"
|
40 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
41 |
+
output = model(**encoded_input)
|
42 |
+
scores = output[0][0].detach().numpy()
|
43 |
+
scores = softmax(scores)
|
44 |
+
|
45 |
+
# # TF
|
46 |
+
# model = TFAutoModelForSequenceClassification.from_pretrained(MODEL)
|
47 |
+
# model.save_pretrained(MODEL)
|
48 |
+
|
49 |
+
# text = "Good night π"
|
50 |
+
# encoded_input = tokenizer(text, return_tensors='tf')
|
51 |
+
# output = model(encoded_input)
|
52 |
+
# scores = output[0][0].numpy()
|
53 |
+
# scores = softmax(scores)
|
54 |
+
|
55 |
+
ranking = np.argsort(scores)
|
56 |
+
ranking = ranking[::-1]
|
57 |
+
for i in range(scores.shape[0]):
|
58 |
+
l = labels[ranking[i]]
|
59 |
+
s = scores[ranking[i]]
|
60 |
+
print(f"{i+1}) {l} {np.round(float(s), 4)}")
|
61 |
+
|
62 |
+
```
|
63 |
+
|
64 |
+
Output:
|
65 |
+
|
66 |
+
```
|
67 |
+
1) π 0.2637
|
68 |
+
2) β€οΈ 0.1952
|
69 |
+
3) π 0.1171
|
70 |
+
4) β¨ 0.0927
|
71 |
+
5) π 0.0756
|
72 |
+
6) π 0.046
|
73 |
+
7) π 0.0444
|
74 |
+
8) π 0.0272
|
75 |
+
9) π 0.0228
|
76 |
+
10) π 0.0198
|
77 |
+
11) π 0.0166
|
78 |
+
12) π 0.0132
|
79 |
+
13) π 0.0131
|
80 |
+
14) β 0.0112
|
81 |
+
15) π 0.009
|
82 |
+
16) π― 0.009
|
83 |
+
17) π₯ 0.008
|
84 |
+
18) π· 0.0057
|
85 |
+
19) πΊπΈ 0.005
|
86 |
+
20) πΈ 0.0048
|
87 |
+
```
|
config.json
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "tweeteval/roberta-base-rt-emotion/",
|
3 |
+
"architectures": [
|
4 |
+
"RobertaForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"bos_token_id": 0,
|
8 |
+
"eos_token_id": 2,
|
9 |
+
"gradient_checkpointing": false,
|
10 |
+
"hidden_act": "gelu",
|
11 |
+
"hidden_dropout_prob": 0.1,
|
12 |
+
"hidden_size": 768,
|
13 |
+
"id2label": {
|
14 |
+
"0": "LABEL_0",
|
15 |
+
"1": "LABEL_1",
|
16 |
+
"2": "LABEL_2",
|
17 |
+
"3": "LABEL_3"
|
18 |
+
},
|
19 |
+
"initializer_range": 0.02,
|
20 |
+
"intermediate_size": 3072,
|
21 |
+
"label2id": {
|
22 |
+
"LABEL_0": 0,
|
23 |
+
"LABEL_1": 1,
|
24 |
+
"LABEL_2": 2,
|
25 |
+
"LABEL_3": 3
|
26 |
+
},
|
27 |
+
"layer_norm_eps": 1e-05,
|
28 |
+
"max_position_embeddings": 514,
|
29 |
+
"model_type": "roberta",
|
30 |
+
"num_attention_heads": 12,
|
31 |
+
"num_hidden_layers": 12,
|
32 |
+
"pad_token_id": 1,
|
33 |
+
"type_vocab_size": 1,
|
34 |
+
"vocab_size": 50265
|
35 |
+
}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:edb772ba5d90a4e7156ae8124ff2528918d033bff8964fc66acaf042f1539e41
|
3 |
+
size 498682569
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": "<mask>"}
|
tf_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:15c16231fa893126aa085c263fc0afb2fee80f0fd1faec4fc94a2188d7df4787
|
3 |
+
size 501233376
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|