Update README.md
Browse files
README.md
CHANGED
@@ -1,46 +1,71 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
-
|
4 |
-
model-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
##
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# tweet-topic-21-single
|
2 |
+
|
3 |
+
This is a roBERTa-base model trained on ~124M tweets from January 2018 to December 2021 (see [here](https://huggingface.co/cardiffnlp/twitter-roberta-base-2021-124m)), and finetuned for single-label topic classification on a corpus of 6,997 tweets.
|
4 |
+
The original roBERTa-base model can be found [here](https://huggingface.co/cardiffnlp/twitter-roberta-base-2021-124m) and the original reference paper is [TweetEval](https://github.com/cardiffnlp/tweeteval). This model is suitable for English.
|
5 |
+
|
6 |
+
- Reference Paper: [TimeLMs paper](https://arxiv.org/abs/2202.03829).
|
7 |
+
- Git Repo: [TimeLMs official repository](https://github.com/cardiffnlp/timelms).
|
8 |
+
|
9 |
+
<b>Labels</b>:
|
10 |
+
- 0 -> arts_&_culture;
|
11 |
+
- 1 -> business_&_entrepreneurs;
|
12 |
+
- 2 -> pop_culture;
|
13 |
+
- 3 -> daily_life;
|
14 |
+
- 4 -> sports_&_gaming;
|
15 |
+
- 5 -> science_&_technology
|
16 |
+
|
17 |
+
|
18 |
+
## Full classification example
|
19 |
+
|
20 |
+
```python
|
21 |
+
from transformers import AutoModelForSequenceClassification, TFAutoModelForSequenceClassification
|
22 |
+
from transformers import AutoTokenizer
|
23 |
+
import numpy as np
|
24 |
+
from scipy.special import softmax
|
25 |
+
|
26 |
+
|
27 |
+
MODEL = f"cardiffnlp/tweet-topic-21-single"
|
28 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
29 |
+
|
30 |
+
# PT
|
31 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
32 |
+
class_mapping = model.config.id2label
|
33 |
+
|
34 |
+
text = "Tesla stock is on the rise!"
|
35 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
36 |
+
output = model(**encoded_input)
|
37 |
+
|
38 |
+
output = model(**encoded_input)
|
39 |
+
scores = output[0][0].detach().numpy()
|
40 |
+
scores = softmax(scores)
|
41 |
+
|
42 |
+
# TF
|
43 |
+
#model = TFAutoModelForSequenceClassification.from_pretrained(MODEL)
|
44 |
+
#class_mapping = model.config.id2label
|
45 |
+
#text = "Tesla stock is on the rise!"
|
46 |
+
#encoded_input = tokenizer(text, return_tensors='tf')
|
47 |
+
#output = model(**encoded_input)
|
48 |
+
#output = model(**encoded_input)
|
49 |
+
#scores = output[0][0]
|
50 |
+
#scores = softmax(scores)
|
51 |
+
|
52 |
+
|
53 |
+
ranking = np.argsort(scores)
|
54 |
+
ranking = ranking[::-1]
|
55 |
+
for i in range(scores.shape[0]):
|
56 |
+
l = class_mapping[ranking[i]]
|
57 |
+
s = scores[ranking[i]]
|
58 |
+
print(f"{i+1}) {l} {np.round(float(s), 4)}")
|
59 |
+
|
60 |
+
```
|
61 |
+
|
62 |
+
Output:
|
63 |
+
|
64 |
+
```
|
65 |
+
1) business_&_entrepreneurs 0.8361
|
66 |
+
2) science_&_technology 0.0904
|
67 |
+
3) pop_culture 0.0288
|
68 |
+
4) daily_life 0.0178
|
69 |
+
5) arts_&_culture 0.0137
|
70 |
+
6) sports_&_gaming 0.0133
|
71 |
+
```
|