Upload README.md
Browse filesAdding model card
README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# roberta_sentiments_es_en , A Sentiment Analysis model for Spanish sentences
|
| 2 |
+
|
| 3 |
+
This is a roBERTa-base model trained on ~58M tweets and finetuned for sentiment analysis. This model currently supports Spanish sentences
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
## Example of classification
|
| 7 |
+
|
| 8 |
+
```python
|
| 9 |
+
from transformers import AutoModelForSequenceClassification
|
| 10 |
+
from transformers import TFAutoModelForSequenceClassification
|
| 11 |
+
from transformers import AutoTokenizer
|
| 12 |
+
import numpy as np
|
| 13 |
+
import pandas as pd
|
| 14 |
+
from scipy.special import softmax
|
| 15 |
+
|
| 16 |
+
MODEL = 'Manauu17/roberta_sentiments_es_en'
|
| 17 |
+
|
| 18 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 19 |
+
|
| 20 |
+
# PyTorch
|
| 21 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
| 22 |
+
|
| 23 |
+
text = ['@usuario siempre es bueno la opinión de un playo',
|
| 24 |
+
'Bendito año el que me espera']
|
| 25 |
+
|
| 26 |
+
encoded_input = tokenizer(text, return_tensors='pt', padding=True, truncation=True)
|
| 27 |
+
output = model(**encoded_input)
|
| 28 |
+
scores = output[0].detach().numpy()
|
| 29 |
+
|
| 30 |
+
# TensorFlow
|
| 31 |
+
model = TFAutoModelForSequenceClassification.from_pretrained(MODEL)
|
| 32 |
+
|
| 33 |
+
text = ['La guerra no es buena para nadie.','Espero que mi jefe me de mañana libre']
|
| 34 |
+
encoded_input = tokenizer(text, return_tensors='tf', padding=True, truncation=True)
|
| 35 |
+
output = model(encoded_input)
|
| 36 |
+
scores = output[0].numpy()
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# Results
|
| 40 |
+
def get_scores(model_output, labels_dict):
|
| 41 |
+
scores = softmax(model_output)
|
| 42 |
+
frame = pd.DataFrame(scores, columns=labels.values())
|
| 43 |
+
frame.style.highlight_max(axis=1,color="green")
|
| 44 |
+
return frame
|
| 45 |
+
|
| 46 |
+
```
|
| 47 |
+
Output:
|
| 48 |
+
|
| 49 |
+
```
|
| 50 |
+
# PyTorch
|
| 51 |
+
get_scores(scores, labels_dict).style.highlight_max(axis=1, color="green")
|
| 52 |
+
|
| 53 |
+
Negative Neutral Positive
|
| 54 |
+
0 0.000607 0.004851 0.906596
|
| 55 |
+
1 0.079812 0.006650 0.001484
|
| 56 |
+
|
| 57 |
+
# TensorFlow
|
| 58 |
+
get_scores(scores, labels_dict).style.highlight_max(axis=1, color="green")
|
| 59 |
+
|
| 60 |
+
Negative Neutral Positive
|
| 61 |
+
0 0.017030 0.008920 0.000667
|
| 62 |
+
1 0.000260 0.001695 0.971429
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
```
|