Our model's performance (F1: 0.9894) is SOTA. Most documented Spanish CEFR classifiers fall within the 0.75 – 0.88 F1-score range. The obtained results significantly outperform these common baselines:
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_id = "pymlex/roberta-spanish-cefr"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForSequenceClassification.from_pretrained(model_id)
8model.eval()
9
10def predict_cefr(text, top_k=3):
11 inputs = tokenizer(
12 text,
13 return_tensors="pt",
14 truncation=True,
15 max_length=512,
16 )
17 with torch.no_grad():
18 logits = model(**inputs).logits
19 probs = torch.softmax(logits, dim=-1)[0]
20
21 k = min(top_k, probs.numel())
22 values, indices = torch.topk(probs, k=k)
23
24 return [
25 {
26 "label": model.config.id2label[i.item()],
27 "score": float(v.item()),
28 }
29 for i, v in zip(indices, values)
30 ]
31
32text = "Estimados señores, les escribo para solicitar información sobre el curso."
33print(predict_cefr(text, top_k=3))