Mapping of labels:
| Class | Label |
|---|---|
| 0 | Ayuntamiento |
| 1 | Ciencia |
| 2 | Cultura |
| 3 | Deporte |
| 4 | Economía |
| 5 | Educación |
| 6 | Igualdad_Integración |
| 7 | MedioAmbiente |
| 8 | Movilidad |
| 9 | Política |
| 10 | Salud |
| 11 | Sucesos |
| 12 | Tecnología |
| 13 | Turismo |
Evaluation w/ Gold Standard (10%, 5000 messages)
***** Running Prediction ***** Num examples = 5000 Batch size = 16
| precision | recall | f1-score | support | |
|---|---|---|---|---|
| 0 | 0.88 | 0.88 | 0.88 | 312 |
| 1 | 0.77 | 0.80 | 0.78 | 296 |
| 2 | 0.90 | 0.88 | 0.89 | 335 |
| 3 | 0.95 | 0.97 | 0.96 | 361 |
| 4 | 0.92 | 0.88 | 0.90 | 992 |
| 5 | 0.88 | 0.91 | 0.90 | 326 |
| 6 | 0.78 | 0.74 | 0.76 | 54 |
| 7 | 0.84 | 0.82 | 0.83 | 326 |
| 8 | 0.79 | 0.92 | 0.85 | 296 |
| 9 | 0.89 | 0.82 | 0.85 | 382 |
| 10 | 0.85 | 0.85 | 0.85 | 326 |
| 11 | 0.89 | 0.89 | 0.89 | 301 |
| 12 | 0.90 | 0.84 | 0.87 | 378 |
| 13 | 0.83 | 0.91 | 0.87 | 315 |
| -------------- | ----------- | -------- | ---------- | --------- |
| Accuracy | ----- | ----- | 0.856 | 5000 |
| Macro avg | 0.841 | 0.837 | 0.838 | 5000 |
| Weighted avg | 0.856 | 0.856 | 0.855 | 5000 |
!pip install transformers
from transformers.models.auto.modeling_auto import AutoModelForSequenceClassification
from transformers import AutoTokenizer, AutoModel, utils, pipeline
tokenizer = AutoTokenizer.from_pretrained("xlm-roberta-base")
model = AutoModelForSequenceClassification.from_pretrained("Pafebla/XLMroBERTa_clasificacion_noticiasv2", output_attentions=True)
mapping_labels = {0: 'Ayuntamiento', 1: 'Ciencia', 2: 'Cultura', 3: 'Deporte', 4: 'Economía', 5: 'Educación', 6: 'Igualdad_Integración', 7: 'MedioAmbiente', 8: 'Movilidad', 9: 'Política', 10: 'Salud', 11: 'Sucesos', 12: 'Tecnología', 13: 'Turismo'}
text = "La bolsa está cayendo. El PIB está fatal."
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
label_idx = output[0].argmax().item()
predicted_label = mapping_labels[label_idx]
predicted_label