Swedish grammaticality scorer
precise grammatical error detector for Swedish text
2 min readupdated
This model scores Swedish texts on a scale from 0 (poor) to 1 (grammatically correct), predicting error probabilities at the level of individual tokens (sub-word parts). The overall sentence score is calculated using the probability of error absence. Built on AI-Sweden-Models/ModernBERT-base (a compact and fast ModernBERT architecture), the model was trained on a massive database of real and synthetic text pairs. It is useful for educational app developers, editors, and Swedish language researchers for automated text checking.
Key features
- Token-level detection: evaluates each text fragment for errors.
- High speed: processes thousands of samples in seconds even on entry-level GPUs.
- Trained on real data: uses a combination of synthetic texts and real error datasets (DALAJ).
What you can do
- Text checking: integrate into apps for Swedish learners to identify grammar flaws.
- Quality analysis: assess overall sentence proficiency in large Swedish text corpora.
- Linguistic pipelines: use as a component for auto-correction or proofreading.
Example
from transformers import AutoTokenizer, AutoModelForTokenClassification
import torch
tok = AutoTokenizer.from_pretrained("untrue5149/swedish-grammaticality-modernbert-base")
model = AutoModelForTokenClassification.from_pretrained("untrue5149/swedish-grammaticality-modernbert-base").eval()
enc = tok(["Vi måste köper mjölk."], return_tensors="pt")
logits = model(**enc).logits.squeeze(-1)[0, 1:-1] # drop [CLS]/[SEP]
score = torch.nn.functional.logsigmoid(-logits).sum().exp() # P(no token is wrong)
Read more
DetailsBenchmarks: ROC-AUC on test data up to 0.95
Requirements: tested on NVIDIA GeForce RTX 3050 6GB
Data volume: trained on 154,258 sentence pairs
Base model: AI-Sweden-Models/ModernBERT-base (0.15 billion parameters)










Comments