Views
No views yet
twitter-xlm-roberta-base-sentiment model (model, original paper) with a focus on sentiment from politicians' tweets. The original sentiment fine-tuning was done on 8 languages (Ar, En, Fr, De, Hi, It, Sp, Pt) but further training was done using tweets from Members of Parliament from UK (English), Spain (Spanish) and Greece (Greek).1from transformers import AutoModelForSequenceClassification
2from transformers import TFAutoModelForSequenceClassification
3from transformers import AutoTokenizer
4import numpy as np
5from scipy.special import softmax
6
7MODEL = f"cardiffnlp/xlm-twitter-politics-sentiment"
8
9tokenizer = AutoTokenizer.from_pretrained(MODEL)
10
11# PT
12model = AutoModelForSequenceClassification.from_pretrained(MODEL)
13
14text = "Good night 😊"
15text = preprocess(text)
16encoded_input = tokenizer(text, return_tensors='pt')
17output = model(**encoded_input)
18scores = output[0][0].detach().numpy()
19scores = softmax(scores)
20
21# # TF
22# model = TFAutoModelForSequenceClassification.from_pretrained(MODEL)
23# model.save_pretrained(MODEL)
24
25# text = "Good night 😊"
26# encoded_input = tokenizer(text, return_tensors='tf')
27# output = model(encoded_input)
28# scores = output[0][0].numpy()
29# scores = softmax(scores)
30
31# Print labels and scores
32ranking = np.argsort(scores)
33for i in range(scores.shape[0]):
34 s = scores[ranking[i]]
35 print(i, s)
360 0.0048229103
1 0.03117284
2 0.9640044