File size: 18,310 Bytes
27f25da 933e4e4 27f25da 933e4e4 27f25da 3ff74cd 27f25da | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | ---
license: cc-by-4.0
language:
- nb
- 'no'
base_model: NbAiLab/nb-bert-base
pipeline_tag: token-classification
library_name: onnx
tags:
- grammatical-error-correction
- gector
- onnx
- on-device
- norwegian
- bokmal
datasets:
- wikimedia/wikipedia
---
# Proofbird Grammar — Norwegian
`gector-bert-no` · on-device Norwegian (Bokmål) grammar correction
[](https://huggingface.co/spaces/proofbird/try-grammar)
**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.1** (model files as 1.0.0; card update) · run `2026-11-22-0011` · tag [`v1.0.1`](https://huggingface.co/proofbird/gector-bert-no/tree/v1.0.1), 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, rules or settings the second, card or metadata fixes the third.
A GECToR-style sequence tagger for Norwegian Bokmål grammatical error correction, exported to ONNX (fp32) to run on the
CPU. It is the on-device grammar model of [Proofbird](https://proofbird.app), a writing assistant that works wherever you write, and it is
published here so anyone can inspect what runs on their machine. It is trained on Bokmål only; Nynorsk is another written
standard and this model does not cover it.
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
[](https://colab.research.google.com/#fileId=https%3A//huggingface.co/proofbird/gector-bert-no/blob/main/quickstart.ipynb)
No API key, no GPU. One file, [`quickstart.py`](quickstart.py), downloads the model and runs it with ONNX Runtime.
```bash
pip install onnxruntime tokenizers huggingface_hub
```
```python
import importlib.util
from huggingface_hub import hf_hub_download
spec = importlib.util.spec_from_file_location("quickstart", hf_hub_download("proofbird/gector-bert-no", "quickstart.py"))
quickstart = importlib.util.module_from_spec(spec)
spec.loader.exec_module(quickstart)
model = quickstart.Gector("proofbird/gector-bert-no")
corrected, suggestions = model.correct("Barna var rolig og bilen er nytt.")
print(corrected)
print(suggestions)
```
```text
Barna var rolige og bilen er ny.
[{"start": 10, "length": 5, "original": "rolig", "replacement": "rolige"}, {"start": 28, "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 "Barna var rolig og bilen er nytt."` prints every step below.
## What it corrects
`en` and `et` (`en hus` → `et hus`, `et bil` → `en bil`), the adjective's form after `en`/`et`, after a definite word
and before a noun (`et stor hus` → `stort`, `De gammel husene` → `gamle`, `Min nytt bil` → `nye`), the adjective after
`er`/`var`/`blir` in gender and number (`Bilen var rødt` → `rød`, `Barna var rolig` → `rolige`, `Huset er gammel` →
`gammelt`), the present tense and the infinitive (`Jeg lære norsk` → `lærer`, `Jeg vil gjerne lærer` → `lære`,
`Jeg skal reiser` → `reise`), `og` where `å` belongs (`Hun prøver og lese` → `å lese`, `flink til og tegne` → `å`),
compounds written apart (`bok hylle` → `bokhylle`, `jern bane stasjon` → `jernbanestasjon`), a closed set of words that
are often confused (`hvert`/`vært`: `Jeg har hvert der` → `vært`; `vær`/`hver`: `vær dag` → `hver dag`;
`ligger`/`legger` in clear frames: `Hun ligger boken på bordet` → `legger`), missing `æ`, `ø` and `å` (`Vi skal kjore`
→ `kjøre`, `pa` → `på`), 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:** [`NbAiLab/nb-bert-base`](https://huggingface.co/NbAiLab/nb-bert-base) (NB-BERT, the National
Library of Norway, CC BY 4.0). A tagging head (581 edit labels) and an error-detection head sit on top.
- **Data: synthetic only.** Two sources:
- 3 000 000 sentences from Norwegian Bokmål Wikipedia
([`wikimedia/wikipedia`](https://huggingface.co/datasets/wikimedia/wikipedia), `20231101.no`);
- 9 157 sentences from [Tatoeba](https://tatoeba.org), everyday Norwegian (all that pass the length filter, less the
sentences held out for the checks below).
They were corrupted by hand-written Norwegian 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 Norwegian (`får` without its mark is `far`, another word, so
that pair is never taught). A mark is dropped only from everyday words and never from a name, and a name is never
doubled. Real sentences that carry a pattern the model needs (a plural subject with its adjective, a verb after a
modal, a compound, `og` before an infinitive) were added again with the error placed exactly there, together with
correct sentences in shapes that are easy to mistake for an error, 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 (134 139 steps, batch 64, learning rate 3e-5) on one NVIDIA L4. Run id `2026-11-22-0011`; the published
weights are the final step.
## How it was measured
| Check | Result |
|---|---|
| Gold set (268 hand-written sentences: 130 with one error each, 138 correct) | **130 fixed, 138 left alone, 0 missed, 0 made worse** |
| Wrong corrections on 4 000 everyday Tatoeba sentences (held out from training) | 1 (0.025%). 18 sentences changed: 15 real mistakes in the test sentences fixed, 2 equally good alternatives, 1 wrong |
| Wrong corrections on 20 000 sentences from Wikipedia articles the model never saw | 11 (0.055%). 123 sentences changed; the others are real mistakes in the text, words doubled by the text extraction, and equally good alternatives |
| One error planted in each of 600 unseen sentences (199 under 20 words, 207 of 20–39, 194 of 40 or more) | 94.5% fixed (95.0%, 94.2%, 94.3%) |
| 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 model's own confidence setting (`min_error_prob` 0.8 in `gector-meta.json`: an edit the model
is less than 80% sure of is not made) and the apply-side guards in `gector-guards.json`, with the Norwegian (nb-NO)
Hunspell dictionary as the guards' word list. Every changed sentence was checked by hand, by a reader who is not a
native speaker. Without the setting and the guards the model fixes the same 130 gold errors, fixes 96.2% of the planted
ones, and changes 30 Tatoeba and 201 Wikipedia sentences instead of 18 and 123. The model was trained for precision: a
missed error costs less than a wrong correction.
**How to read the two wrong-correction rates.** The confidence setting and the guards were chosen on the same test
sentences they are scored on, so a fresh sample is likely to read a little higher. The gold set and the planted errors
do not depend on that choice.
**Known wrong corrections.** `og` after a preposition changed to `å` where two verbs are joined (`kan arbeide med og
dele de samme dataene` → `å dele`); an adjective that agrees with the wrong word (`netto nåverdi av tiltaket er
positiv` → `positivt`, `mens hardt mellomrom brukes` → `harde`); `en` and `et` on a compound whose last part it
misreads (`i en metalleder` → `et`); a verb after a name that looks like a modal (`Kan drifter åtte radiokanaler` →
`drifte`); two words of a title joined (`Til andakt hjertet vel bered` → `andakthjertet`); a mark put on a compound
that is correct without it (`Skolematen` → `Skolemåten`); a title made of one word twice at the start of a sentence
(`Boing Boing sammenlignet`) loses one.
**Known misses.** `ligger`/`legger` is corrected only where a following word decides it (`Hun ligger boken på bordet`
→ `legger`); `Boken legger på bordet` is left alone. A single error is left untouched about 3 times in 100, at every
sentence length. A doubled foreign word in a foreign phrase is left alone in the app. 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. A word is deleted only when it is written
twice, and `det det` stays (`ikke lenger det det var`); a repeated name stays (`La La Land`, `Li Li`), and so does a
repeated word the dictionary does not know when it stands next to another one (`Tegeozetes tunicatus tunicatus`); a
mark is put on a letter, and two words are joined, only when the result is a word the dictionary knows, and never when
the two words begin alike (`grotte grotta`); two `-t` forms side by side are left as they are (`litt vagt, bredt
uthulet`); an adjective right before a name keeps its ending (`vanlig Nintendo Switch`); `en enkelt` stays. Five of
these need the Norwegian dictionary, which the app downloads with the model.
## Files
| File | What it is |
|---|---|
| `model.onnx` | The tagger (fp32, opset 17). Inputs `input_ids`, `attention_mask`; outputs `logits_labels` [1, T, 581] 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, run id, and the decoding defaults - among them the model's confidence setting, `min_error_prob` 0.8. |
| `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, and a text without one gets one for the model only. |
| `verb-form-vocab.txt` | Empty for Norwegian: 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 (`kjore` + `1ø` → `kjøre`; `æ` and `ø` count as `a` and `o`); `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 581 tags such as `$KEEP`, `$DELETE`, `$APPEND_av`, `$REPLACE_doble` or `$TRANSFORM_SUF__e` (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: `Barna var rolig og bilen er 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.
```text
words $START Barna var rolig og bilen er nytt .
tokens [CLS] Barn ##a var roli ##g og bilen er nytt . [SEP]
input_ids [101, 61802, 10113, 10299, 30252, 10240, 10156, 109842, 10163, 32991, 119, 102]
attention_mask [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
```
Two inputs, both whole numbers (int64), shape `[1, 12]`: one sentence of 12 tokens.
**3. The response.** Two outputs (float32): `logits_labels` `[1, 12, 581]`, a score for each of the 581 edits at every token, and `logits_d` `[1, 12, 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:* `Barna var rolig og bilen er nytt.`
| Word | Wrong | Chosen edit | Probability |
|---|---|---|---|
| $START | 0.0% | $KEEP | 100.0% |
| Barna | 0.0% | $KEEP | 100.0% |
| var | 0.0% | $KEEP | 100.0% |
| rolig | 99.5% | **$TRANSFORM_SUF__e** | 99.5% |
| og | 0.0% | $KEEP | 100.0% |
| bilen | 0.0% | $KEEP | 100.0% |
| er | 0.0% | $KEEP | 100.0% |
| nytt | 100.0% | **$TRANSFORM_SUF_tt_** | 100.0% |
| . | 0.0% | $KEEP | 100.0% |
→ `Barna var rolige og bilen er ny.`
*Pass 2:* `Barna var rolige og bilen er ny.`
| Word | Wrong | Chosen edit | Probability |
|---|---|---|---|
| $START | 0.0% | $KEEP | 100.0% |
| Barna | 0.0% | $KEEP | 100.0% |
| var | 0.0% | $KEEP | 100.0% |
| rolige | 0.0% | $KEEP | 100.0% |
| og | 0.0% | $KEEP | 100.0% |
| bilen | 0.0% | $KEEP | 100.0% |
| er | 0.0% | $KEEP | 100.0% |
| ny | 0.0% | $KEEP | 100.0% |
| . | 0.0% | $KEEP | 100.0% |
→ `Barna var rolige og bilen er 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=None, min_error_prob=None)` takes the two GECToR precision knobs. Left out, they come from the model's own `gector-meta.json`: this model sets `min_error_prob` to 0.8, and the Proofbird app reads the same value (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. At the model's own 0.8 the example is corrected as shown: the model is 100.0% sure one word is wrong. With `min_error_prob=0` every edit the model prefers is applied (the example comes out the same): more real mistakes are fixed and more wrong corrections are made - the figures are under *How it was measured*.
**Reading `min_error_prob`.** It is a number from 0 to 1: how sure the model must be that something is wrong before it changes anything. At 0.5 it acts when it is at least 50% sure, at 0.7 when it is at least 70% sure. A higher number is stricter: fewer wrong corrections, and some real mistakes are left alone. A lower number is looser: more mistakes are fixed, and more wrong corrections are made. Each model carries the value that gave the best balance on its own tests; this one carries 0.8.
## What Proofbird adds
`quickstart.py` is the model on its own. The [Proofbird](https://proofbird.app) 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 Norwegian and their word lists; what each guard does is code in the app. The scores under *How it was measured* are with the guards.
- **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 on its own, without the guards.
## Licence and attribution
The model weights and the files in this repository are released under the
[Creative Commons Attribution 4.0 International licence](LICENSE) (CC BY 4.0), the licence of the base encoder. If you
redistribute the model or a model built from it, keep the [NOTICE](NOTICE) file with it.
The base encoder is NB-BERT, `NbAiLab/nb-bert-base`, by Per E. Kummervold, Javier de la Rosa, Freddy Wetjen and Svein
Arne Brygfjeld (the National Library of Norway), CC BY 4.0: *Operationalizing a National Digital Library: The Case for
a Norwegian Transformer Model*, NoDaLiDa 2021.
The fine-tuning data carries its own terms. Wikipedia text is © Wikipedia contributors,
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/). Tatoeba sentences are from
[tatoeba.org](https://tatoeba.org), [CC BY 2.0 FR](https://creativecommons.org/licenses/by/2.0/fr/). 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:
```bibtex
@misc{hartnett2026gectorno,
author = {Hartnett, Patrick Andrew},
title = {Proofbird GECToR grammar model (Norwegian)},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/proofbird/gector-bert-no}},
note = {Proofbird, https://proofbird.app}
}
```
If you build on this model, a link back to this page is appreciated. If you use it in a product or service, please credit it where your users can see it, for example *Grammar checking by Proofbird (https://proofbird.app)*.
## Contact
Published by Patrick Andrew Hartnett as personal work. Questions and reports: open a discussion on this repository.
|