Proofbird Grammar — Swedish

gector-bert-sv · on-device Swedish grammar correction

Try it in your browser

Try it in your browser: type a sentence and see the corrections. The model runs on your own computer; nothing to install, and your text never leaves the page.

Version 1.0.0 · run 2026-11-20-0657 · tag v1.0.0, the files the Proofbird app downloads. Pin it with revision="v1.0.0". Versions: a change to the model's design (encoder, inputs, outputs) raises the first number, a new training run or changed guards and rules the second, card or metadata fixes the third.

A GECToR-style sequence tagger for Swedish grammatical error correction, exported to ONNX (fp32) to run on the CPU. It is the on-device grammar model of Proofbird, a writing assistant for Windows, and it is published here so anyone can inspect what runs on their machine.

GECToR does not rewrite text. For each token it predicts one edit tag (keep, delete, replace with a word, append a word, change case, change a word's ending, put a letter's marks back), and the edits are applied and the sentence re-tagged up to five times. The tagger only proposes local edits; it never paraphrases.

Quick start

Open in Colab

No API key, no GPU. One file, quickstart.py, downloads the model and runs it with ONNX Runtime.

pip install onnxruntime tokenizers huggingface_hub
import importlib.util
from huggingface_hub import hf_hub_download

spec = importlib.util.spec_from_file_location("quickstart", hf_hub_download("proofbird/gector-bert-sv", "quickstart.py"))
quickstart = importlib.util.module_from_spec(spec)
spec.loader.exec_module(quickstart)

model = quickstart.Gector("proofbird/gector-bert-sv")
corrected, suggestions = model.correct("Barnen var lugn och bilen är nytt.")
print(corrected)
print(suggestions)
Barnen var lugna och bilen är ny.
[{"start": 11, "length": 4, "original": "lugn", "replacement": "lugna"}, {"start": 29, "length": 4, "original": "nytt", "replacement": "ny"}]

Each suggestion gives the character position in your text (start, length), what is there now (original) and what to put instead (replacement), so you can underline it and offer the fix. From the command line: python quickstart.py "Barnen var lugn och bilen är nytt." prints every step below.

What it corrects

en and ett (en hus → ett hus, ett bil → en bil), the adjective's form after en/ett, after a definite word and before a noun (ett stor hus → stort, den stor bilen → stora, min nya bil kept), the adjective after är/var/blir in gender and number (Bilen är nytt → ny, Barnen var lugn → lugna, Husen är gammal → gamla), de and dem (Jag gav boken till de → dem, Dem kommer i morgon → De), the present tense and the infinitive (Jag spela fotboll → spelar, Jag vill spelar → spela, att läser → läsa), compounds written apart (hus ägare → husägare, skatte sänkning → skattesänkning), missing å, ä and ö (Vi ska aka buss → åka, fran → från), a word written twice, and a capital at the start of a sentence. It reads a sentence typed without a final full stop the same way as one with it.

How it was trained

  • Base encoder: KBLab/bert-base-swedish-cased (KB-BERT, the National Library of Sweden, CC0-1.0). A tagging head (8 000 edit labels) and an error-detection head sit on top.

  • Data: synthetic only. Three sources, 3 036 306 sentences in all:

    • 1 500 000 sentences from Swedish Wikipedia (wikimedia/wikipedia, 20231101.sv), with machine-written stub articles left out;
    • 1 500 000 sentences from the proceedings of the European Parliament (Europarl v8 through OPUS, sessions before June 2011): speech in the first and second person, questions and argument, the register encyclopedic text lacks;
    • 36 306 sentences from Tatoeba, everyday Swedish (all that pass the length filter, less the sentences held out for the checks below).

    They were corrupted by hand-written Swedish error rules, mostly one error per sentence whatever its length; about 10% stay clean, so the model learns to leave correct text alone. Each rule was run over real text first and changed wherever the "error" it made also occurs as correct Swedish. Real sentences that carry a pattern the model needs (a plural subject with its adjective, dem after a preposition, a compound) were added again with the error placed exactly there, and 150 000 template sentences teach patterns the corpora rarely contain. One training sentence in seven has no final full stop.

  • No learner corpora and no non-commercial data in the fine-tuning. No user text was used.

  • One epoch (122 507 steps, batch 64, learning rate 3e-5) on one NVIDIA L4. Run id 2026-11-20-0657; the published weights are the checkpoint at step 120 000.

How it was measured

Check Result
Gold set (180 hand-written sentences: 110 with one error each, 70 correct) 110 fixed, 70 left alone, 0 missed, 0 made worse
Wrong corrections on 4 000 everyday Tatoeba sentences (held out from training) 3 (0.075%). 7 sentences changed: 3 real mistakes in the test sentences fixed, 1 equally good alternative, 3 wrong
Wrong corrections on 20 000 sentences from European Parliament sessions the model never saw (June 2011 on) 8 (0.04%). 34 sentences changed: 23 real mistakes fixed, 3 equally good alternatives, 8 wrong
One error planted in each of 600 unseen sentences (199 under 20 words, 207 of 20–39, 194 of 40 or more) 99.3% fixed (99.0%, 99.5%, 99.5%)
Stability: the gold re-run with one extra token in front of each sentence 0 sentences change result (the 3 capitalisation rows change by construction and are not counted)

The scores are with the apply-side guards in gector-guards.json and the one rule below. Every changed sentence was checked by hand. On its own the model fixes 108 of the 110 gold errors and changes 9 Tatoeba and 44 Europarl sentences. The model was trained for precision: a missed error costs less than a wrong correction.

Known wrong corrections. An adjective or participle that agrees with the wrong word in a long sentence (Fas ett är slutförd → slutfört, hur viktiga detta förslag och miljöräkenskaperna är → viktigt); an accent put on a word that is correct without it (Stal du den här? → Stål); two nouns the writer meant apart joined into a compound the dictionary accepts (gränspolis säkerhetssystem). The gold set was written for this model and has not yet been reviewed by a native speaker. It has not been measured on learner essays.

The guards. gector-guards.json holds back edits we measured as wrong in a known shape. They run in the Proofbird app (not in quickstart.py or the demo) and are part of every score above. An adjective form that ends its clause changes only when är, var, blir or a similar verb stands before it (tolkas som icke godkänt stays); after det, den, de or a possessive the -a form stays (det direkta frikopplade stödet); two words are joined only into a word the dictionary knows; a word is deleted only when it is written twice; an accent is added only when the result is a word.

Files

File What it is
model.onnx The tagger (fp32, opset 17). Inputs input_ids, attention_mask; outputs logits_labels [1, T, 8000] and logits_d [1, T, 2].
config.json The edit-label vocabulary (id2label).
vocab.txt, tokenizer.json, tokenizer_config.json The base encoder's WordPiece tokenizer.
gector-meta.json Export facts: encoder, tokenizer family, decoding defaults, run id, version.
gector-guards.json Apply-side guards: rules that hold back an edit the model gets wrong in a known way, with their word lists. Part of the measured result.
language-rules.json Language facts the runtime needs: the final full stop stays on, a text without one gets one for the model only, and the verb table for De + infinitive.
verb-form-vocab.txt Empty for Swedish: verb forms are corrected with ending tags, not a verb table.
quickstart.py A complete Python runner: download, tokenize, run, decode, apply, suggestions. See Quick start.
quickstart.ipynb The same, as a notebook (the Open in Colab button).

The Proofbird app runs the same algorithm in C# with ONNX Runtime; the files are standard, so any GECToR-style decoder can use them. One tag family is specific to this model: $TRANSFORM_DIA_<n><letter> puts a mark back on the n-th letter with that base letter (jarnvagen + 1ä2ä → järnvägen); quickstart.py shows how it is applied.

How it works, step by step

The model never sees letters and never writes text. It reads numbers (token ids) and answers, for every word, which edit to make: one of 8 000 tags such as $KEEP, $DELETE, $APPEND_är, $REPLACE_affär or $TRANSFORM_SUF__a (change a word's ending). quickstart.py does everything around it. This is the real run of the example above.

1. Prepare the text. The sentence goes in as written (a text typed without a final full stop is shown to the model with one, which is taken off again - language-rules.json): Barnen var lugn och bilen är nytt..

2. The request. The words are looked up in the model's dictionary (vocab.txt). A rare word is split into pieces; the edit is read at its first piece. [CLS] stands for a dummy first word, $START, so an edit on it can add a word at the very beginning; [SEP] marks the end.

words           $START  Barnen  var  lugn  och  bilen  är  nytt  .
tokens          [CLS] Barnen var lugn och bilen är nytt . [SEP]
input_ids       [2, 10147, 96, 4669, 36, 3197, 54, 1369, 7, 3]
attention_mask  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

Two inputs, both whole numbers (int64), shape [1, 10]: one sentence of 10 tokens.

3. The response. Two outputs (float32): logits_labels [1, 10, 8000], a score for each of the 8 000 edits at every token, and logits_d [1, 10, 2], a score for "this word is correct" and "this word is wrong". A softmax turns each row into probabilities; the most probable edit at each word's first token is the one applied.

4. Pass by pass. The corrected sentence goes back in, until a pass changes nothing (at most five passes). Connected errors are fixed one after the other.

Pass 1: Barnen var lugn och bilen är nytt.

Word Wrong Chosen edit Probability
$START 0.0% $KEEP 100.0%
Barnen 0.0% $KEEP 100.0%
var 0.0% $KEEP 100.0%
lugn 100.0% $TRANSFORM_SUF__a 100.0%
och 0.0% $KEEP 100.0%
bilen 0.0% $KEEP 100.0%
är 0.0% $KEEP 100.0%
nytt 100.0% $TRANSFORM_SUF_tt_ 100.0%
. 0.0% $KEEP 100.0%

→ Barnen var lugna och bilen är ny.

Pass 2: Barnen var lugna och bilen är ny.

Word Wrong Chosen edit Probability
$START 0.0% $KEEP 100.0%
Barnen 0.0% $KEEP 100.0%
var 0.0% $KEEP 100.0%
lugna 0.0% $KEEP 100.0%
och 0.0% $KEEP 100.0%
bilen 0.0% $KEEP 100.0%
är 0.0% $KEEP 100.0%
ny 0.0% $KEEP 100.0%
. 0.0% $KEEP 100.0%

→ Barnen var lugna och bilen är ny. — no change, so it stops.

5. The suggestions. The original and the final words are compared, and each changed stretch becomes one suggestion with its position in the original text (unchanged text keeps its own spacing), as in the Quick start output above.

6. Settings. Gector(repo, keep_confidence=0.0, min_error_prob=0.0) takes the two GECToR precision knobs (the Proofbird app runs with both at 0, and at most five passes):

  • keep_confidence adds a bonus to $KEEP before choosing: higher means fewer, safer edits.
  • min_error_prob ignores an edit the model is less sure of, and leaves the whole sentence alone when no word is at least that likely to be wrong. With min_error_prob=0.9 the example is still corrected (Barnen var lugna och bilen är ny.): the model is 100.0% sure one word is wrong.

What Proofbird adds

quickstart.py is the model on its own. The Proofbird app runs the same algorithm in C# and adds:

  • Guards: per-language rules that hold back edits we measured as wrong in a known shape. gector-guards.json, in this repository, lists which guards are on for Swedish and their word lists; what each guard does is code in the app. The scores under How it was measured are with the guards.
  • One rule for a shape the model leaves alone: De + an infinitive at the start of a sentence becomes the present (De spela fotboll → De spelar fotboll). The verb table is in language-rules.json. This rule is also in quickstart.py and the in-browser demo, because it adds a correction.
  • Spelling, checked separately by the operating system's spell checker; the guards use it so a grammar edit is not made on a word that is misspelled.
  • A card for each change that names the error ("Subject–verb agreement") and, on request, explains it.

quickstart.py and the in-browser demo run the model with that one rule and without the guards.

Licence and attribution

The model weights and the files in this repository are released under the Apache License 2.0. If you redistribute the model or a model built from it, keep the NOTICE file with it (Apache-2.0, section 4(d)).

The training data carries its own terms. Wikipedia text is © Wikipedia contributors, CC BY-SA 4.0. Tatoeba sentences are from tatoeba.org, CC BY 2.0 FR. Contains text from the proceedings of the European Parliament, © European Union, 1996–2011, reused under the European Parliament's legal notice, through the Europarl corpus (statmt.org/europarl, Philipp Koehn, Europarl: A Parallel Corpus for Statistical Machine Translation, MT Summit 2005) as distributed by OPUS (opus.nlpl.eu, Jörg Tiedemann, Parallel Data, Tools and Interfaces in OPUS, LREC 2012). The base encoder is KB-BERT, KBLab/bert-base-swedish-cased, by Martin Malmsten, Love Börjeson and Chris Haffenden (KBLab, the National Library of Sweden), CC0-1.0: Playing with Words at the National Library of Sweden – Making a Swedish BERT, arXiv:2007.01658, 2020. The tagging scheme follows GECToR (Omelianchuk et al., 2020, GECToR – Grammatical Error Correction: Tag, Not Rewrite).

How to cite

If you use or build on this model, please cite it:

@misc{hartnett2026gectorsv,
  author       = {Hartnett, Patrick Andrew},
  title        = {Proofbird GECToR grammar model (Swedish)},
  year         = {2026},
  publisher    = {Hugging Face},
  howpublished = {\url{https://huggingface.co/proofbird/gector-bert-sv}},
  note         = {Proofbird, https://proofbird.app}
}

If you build on this model, a link back to this page is appreciated.

Contact

Published by Patrick Andrew Hartnett as personal work. Questions and reports: open a discussion on this repository.

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for proofbird/gector-bert-sv

Quantized
(2)
this model

Dataset used to train proofbird/gector-bert-sv

Space using proofbird/gector-bert-sv 1

Paper for proofbird/gector-bert-sv