Views
No views yet
1{
2 'test_loss': 0.14830373227596283
3 'test_accuracy': 0.9415
4 'test_f1': 0.9411005763302622
5 'test_runtime': 8.372
6 'test_samples_per_second': 238.892
7 'test_steps_per_second': 3.822
8 }1from transformers import pipeline
2model_path = "daveni/twitter-xlm-roberta-emotion-es"
3emotion_analysis = pipeline("text-classification", framework="pt", model=model_path, tokenizer=model_path)
4emotion_analysis("Einstein dijo: Solo hay dos cosas infinitas, el universo y los pinches anuncios de bitcoin en Twitter. Paren ya carajo aaaaaaghhgggghhh me quiero murir")[{'label': 'anger', 'score': 0.48307016491889954}]1from transformers import AutoModelForSequenceClassification
2from transformers import AutoTokenizer, AutoConfig
3import numpy as np
4from scipy.special import softmax
5# Preprocess text (username and link placeholders)
6def preprocess(text):
7 new_text = []
8 for t in text.split(" "):
9 t = '@user' if t.startswith('@') and len(t) > 1 else t
10 t = 'http' if t.startswith('http') else t
11 new_text.append(t)
12 return " ".join(new_text)
13model_path = "Cesar42/bert-base-uncased-emotion_v2"
14tokenizer = AutoTokenizer.from_pretrained(model_path )
15config = AutoConfig.from_pretrained(model_path )
16# PT
17model = AutoModelForSequenceClassification.from_pretrained(model_path )
18text = "Se ha quedao bonito día para publicar vídeo, ¿no? Hoy del tema más diferente que hemos tocado en el canal."
19text = preprocess(text)
20print(text)
21encoded_input = tokenizer(text, return_tensors='pt')
22output = model(**encoded_input)
23scores = output[0][0].detach().numpy()
24scores = softmax(scores)
25# Print labels and scores
26ranking = np.argsort(scores)
27ranking = ranking[::-1]
28for i in range(scores.shape[0]):
29 l = config.id2label[ranking[i]]
30 s = scores[ranking[i]]
31 print(f"{i+1}) {l} {np.round(float(s), 4)}")Se ha quedao bonito día para publicar vídeo, ¿no? Hoy del tema más diferente que hemos tocado en el canal.
1) joy 0.7887
2) others 0.1679
3) surprise 0.0152
4) sadness 0.0145
5) anger 0.0077
6) disgust 0.0033
7) fear 0.0027