Swedish Grammaticality Scoring — ModernBERT-large (Chunk1e/swedish-grammaticality-modernbert-large)

A fine-tuned AI-Sweden-Models/ModernBERT-large (395.83M parameters) regression model that scores the grammatical correctness of Swedish text on a continuous scale in [0, 1] (higher = more grammatical).

Built for the AI Sweden Master's Thesis Selection Task — Swedish Grammaticality Scoring.

Usage

import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

model_id = "Chunk1e/swedish-grammaticality-modernbert-large"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id).eval()

texts = [
    "Kommunen har beslutat att bygga en ny förskola i stadsdelen, och arbetet beräknas vara klart till hösten nästa år.",
    "I norröna tid fanns det svält i Oslo och många människor dog inte hade fisk tillgång från England.",
]
enc = tokenizer(texts, padding=True, truncation=True, max_length=512, return_tensors="pt")
with torch.inference_mode():
    scores = torch.sigmoid(model(**enc).logits.squeeze(-1)).tolist()
print(scores)

Evaluation Results

Measured on NVIDIA GeForce RTX 4070 SUPER (BF16) and Intel Core i5-13600KF CPU:

Benchmark N Spearman ROC-AUC MAE Throughput
Starter Test (evaluate.py end-to-end incl. load) 120 0.856 0.981 0.063 816 samples/min (8.8s GPU; 5.65s CPU excl. Python cold start)
DaLAJ Dev (real human L2 Swedish) 4,536 0.758 0.938 0.104 78,605 samples/min (GPU)
DaLAJ Test (strictly blind human L2 Swedish) 4,223 0.767 0.942 0.100 79,453 samples/min (GPU)
Graded Val (DaLAJ + Wiki 0/1/2/3 errors) 2,000 0.896 0.976 0.083 54,307 samples/min (GPU)

Training Details

  • Loss: Soft BCEWithLogitsLoss on continuous targets in [0, 1] + in-batch pairwise logistic ranking loss (rank_weight=0.25, score gap >= 0.10).
  • Data: 66,492 zero-leakage examples combining full balanced DaLAJ-GED (33,536), graded synthetic multi-error DaLAJ (16,000), graded synthetic multi-error native Swedish Wikipedia sentences & paragraphs (16,000), and starter train.jsonl (478 × 2).
  • Hyperparameters: 3 epochs, effective batch size 32 (16 × 2), lr=2e-5 (head ×3), cosine schedule (8% warmup), max_length=256, BF16 AMP, seed=42.
Downloads last month
-
Safetensors
Model size
0.4B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Chunk1e/swedish-grammaticality-modernbert-large

Finetuned
(5)
this model

Datasets used to train Chunk1e/swedish-grammaticality-modernbert-large