Downloads · 30 days
16
2% of all-time downloads
cardiffnlp/tweet-topic-19-single
tweet-topic-19-single is a text classification model from cardiffnlp. Use it when you need a label for a piece of text. It is set up for transformers.
This is a roBERTa-base model trained on ~90m tweets until the end of 2019 (see here), and finetuned for single-label topic classification on a corpus of 6,997 tweets. The original roBERTa-base model can be found here…
Downloads · 30 days
16
2% of all-time downloads
All-time downloads
838
Public
Repo size
2 GB
Likes
1
Public
Click a slice to open those files.
.h5499 MB · 50%
From the Hugging Face model README
This is a roBERTa-base model trained on ~90m tweets until the end of 2019 (see here), and finetuned for single-label topic classification on a corpus of 6,997 tweets. The original roBERTa-base model can be found here and the original reference paper is TweetEval. This model is suitable for English.
<b>Labels</b>:
from transformers import AutoModelForSequenceClassification, TFAutoModelForSequenceClassification
from transformers import AutoTokenizer
import numpy as np
from scipy.special import softmax
MODEL = f"cardiffnlp/tweet-topic-19-single"
tokenizer = AutoTokenizer.from_pretrained(MODEL)
# PT
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
class_mapping = model.config.id2label
text = "Tesla stock is on the rise!"
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
scores = output[0][0].detach().numpy()
scores = softmax(scores)
# TF
#model = TFAutoModelForSequenceClassification.from_pretrained(MODEL)
#class_mapping = model.config.id2label
#text = "Tesla stock is on the rise!"
#encoded_input = tokenizer(text, return_tensors='tf')
#output = model(**encoded_input)
#scores = output[0][0]
#scores = softmax(scores)
ranking = np.argsort(scores)
ranking = ranking[::-1]
for i in range(scores.shape[0]):
l = class_mapping[ranking[i]]
s = scores[ranking[i]]
print(f"{i+1}) {l} {np.round(float(s), 4)}")
Output:
1) business_&_entrepreneurs 0.8575
2) science_&_technology 0.0604
3) pop_culture 0.0295
4) daily_life 0.0217
5) sports_&_gaming 0.0154
6) arts_&_culture 0.0154