File size: 18,224 Bytes
0ff5f5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92e9a19
0ff5f5f
 
92e9a19
0ff5f5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8cf8f96
 
0ff5f5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d4a2b77
0ff5f5f
 
 
 
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
---
license: cc-by-4.0
language:
- da
base_model: NbAiLab/nb-bert-base
pipeline_tag: token-classification
library_name: onnx
tags:
- grammatical-error-correction
- gector
- onnx
- on-device
- danish
datasets:
- wikimedia/wikipedia
---

# Proofbird Grammar — Danish

`gector-bert-da` · on-device Danish grammar correction

[![Try it in your browser](https://huggingface.co/datasets/huggingface/badges/resolve/main/open-in-hf-spaces-lg.svg)](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.2** (model files as 1.0.0; card update) · run `2026-11-20-2352` · tag [`v1.0.2`](https://huggingface.co/proofbird/gector-bert-da/tree/v1.0.2), 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 Danish 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.

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](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/#fileId=https%3A//huggingface.co/proofbird/gector-bert-da/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-da", "quickstart.py"))
quickstart = importlib.util.module_from_spec(spec)
spec.loader.exec_module(quickstart)

model = quickstart.Gector("proofbird/gector-bert-da")
corrected, suggestions = model.correct("Børnene var rolig og bilen er nyt.")
print(corrected)
print(suggestions)
```

```text
Børnene var rolige og bilen er ny.
[{"start": 12, "length": 5, "original": "rolig", "replacement": "rolige"}, {"start": 30, "length": 3, "original": "nyt", "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 "Børnene var rolig og bilen er nyt."` 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 huse` → `gamle`, `Min nyt bil` → `nye`), the adjective after
`er`/`var`/`bliver` in gender and number (`Bilen er nyt` → `ny`, `Børnene var rolig` → `rolige`, `Huset er gammel` →
`gammelt`), the present tense and the infinitive (`Jeg lære dansk` → `lærer`, `Jeg vil gerne lærer` → `lære`,
`at læser` → `læse`), compounds written apart (`jern banen` → `jernbanen`, `skatte lettelse` → `skattelettelse`),
`-ene` and `-ende` (`drengende` → `drengene`, `en spændene film` → `spændende`), a closed set of words that are often
confused (`ligger`/`lægger` in clear frames, `nogen`/`nogle`, `af`/`ad`, `end`/`en`, `I`/`i`: `større en mig` → `end`,
`en ting af gangen` → `ad`), missing `æ`, `ø` and `å` (`Vi skal kore` → `kø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). It was chosen by measurement: on 1 200 Danish sentence pairs (one correct, one with an
  error) it preferred the correct one 99.0% of the time, the best of the encoders tried. A tagging head (8 000 edit
  labels) and an error-detection head sit on top.
- **Data: synthetic only.** Three sources, 3 047 281 sentences in all:
  - 1 500 000 sentences from Danish Wikipedia
    ([`wikimedia/wikipedia`](https://huggingface.co/datasets/wikimedia/wikipedia), `20231101.da`);
  - 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;
  - 47 281 sentences from [Tatoeba](https://tatoeba.org), everyday Danish (all that pass the length filter, less the
    sentences held out for the checks below).

  They were corrupted by hand-written Danish 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 Danish (`det er mere en teknisk sag` is right, so `en` → `end` is
  taught only in a comparison). Real sentences that carry a pattern the model needs (a plural subject with its
  adjective, a verb after a modal, 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 (133 378 steps, batch 64, learning rate 3e-5) on one NVIDIA L4. Run id `2026-11-20-2352`; the published
  weights are the checkpoint at step 130 000.

## How it was measured

| Check | Result |
|---|---|
| Gold set (214 hand-written sentences: 120 with one error each, 94 correct) | **118 fixed, 94 left alone, 2 missed, 0 made worse** |
| Wrong corrections on 4 000 everyday Tatoeba sentences (held out from training) | 1 (0.025%). 7 sentences changed: 6 real mistakes in the test sentences fixed, 1 wrong |
| Wrong corrections on 20 000 sentences from European Parliament sessions the model never saw (June 2011 on) | 10 (0.05%). 56 sentences changed: 41 real mistakes fixed, 5 equally good alternatives, 10 wrong |
| One error planted in each of 600 unseen sentences (195 under 20 words, 210 of 20–39, 195 of 40 or more) | 98.5% fixed (100%, 99.5%, 95.9%) |
| 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.95 in `gector-meta.json`: an edit the model
is less than 95% sure of is not made) and the apply-side guards in `gector-guards.json`. Every changed sentence was
checked by hand. Without the setting and the guards the model fixes the same 118 gold errors and changes 17 Tatoeba and
126 Europarl sentences, 7 and 52 of them wrong: it is much less sure of its wrong corrections than of its right ones,
and the setting uses that. It costs some real fixes on text the model was not trained for (about a quarter of the real
mistakes it would otherwise fix in the two test sets) and almost none of the planted ones. 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 guard 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.** An adjective that agrees with the wrong word in a long sentence (`konkurrenceevne er også
meget afhængige af` → `afhængig`, `klart og forståeligt betingelser` → `forståelige`); the polite `De` read as a plural
(`De er usædvanlig gavmild` → `gavmilde`); an accent put on a word that is correct without it (`generositet` →
`generøsitet`); two nouns the writer meant apart joined into one word (`politik kraft`).

**Known misses.** The two missed gold rows are one sentence with an adjective the training never saw (`Aftenerne er
sval`). `ligger`/`lægger` is corrected only where a following word decides it (`lægger bag bjerget` → `ligger`, `ligger
vægt på` → `lægger`); `Bogen lægger på bordet` is left alone. A single error in a sentence of 40 words or more is
missed about 3 times in 100. 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 `til til` and `mange mange` stay (`Lav en til til mig`); a word is replaced only by a word the dictionary
knows.

## 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, run id, and the decoding defaults - among them the model's confidence setting, `min_error_prob` 0.95. |
| `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 Danish: 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 (`kore` + `1ø` → `kø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 8 000 tags such as `$KEEP`, `$DELETE`, `$APPEND_er`, `$REPLACE_ad` 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: `Børnene var rolig og bilen er nyt.`.

**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  Børnene  var  rolig  og  bilen  er  nyt  .
tokens          [CLS] B ##ør ##nene var roli ##g og bilen er nyt . [SEP]
input_ids       [101, 139, 18437, 75160, 10299, 30252, 10240, 10156, 109842, 10163, 58921, 119, 102]
attention_mask  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
```

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

**3. The response.** Two outputs (float32): `logits_labels` `[1, 13, 8000]`, a score for each of the 8 000 edits at every token, and `logits_d` `[1, 13, 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:* `Børnene var rolig og bilen er nyt.`

| Word | Wrong | Chosen edit | Probability |
|---|---|---|---|
| $START | 0.0% | $KEEP | 100.0% |
| Børnene | 0.0% | $KEEP | 100.0% |
| var | 0.0% | $KEEP | 100.0% |
| rolig | 99.8% | **$TRANSFORM_SUF__e** | 99.9% |
| og | 0.0% | $KEEP | 100.0% |
| bilen | 0.0% | $KEEP | 100.0% |
| er | 0.0% | $KEEP | 100.0% |
| nyt | 100.0% | **$TRANSFORM_SUF_t_** | 100.0% |
| . | 0.0% | $KEEP | 100.0% |

→ `Børnene var rolige og bilen er ny.`

*Pass 2:* `Børnene var rolige og bilen er ny.`

| Word | Wrong | Chosen edit | Probability |
|---|---|---|---|
| $START | 0.0% | $KEEP | 100.0% |
| Børnene | 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% |

→ `Børnene 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.95, 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.95 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.95.

## 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 Danish 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/). Contains text
from the proceedings of the European Parliament, © European Union, 1996–2011, reused under the European Parliament's
[legal notice](https://www.europarl.europa.eu/legal-notice/en/), through the Europarl corpus
([statmt.org/europarl](https://www.statmt.org/europarl/), Philipp Koehn, *Europarl: A Parallel Corpus for Statistical
Machine Translation*, MT Summit 2005) as distributed by OPUS ([opus.nlpl.eu](https://opus.nlpl.eu), Jörg Tiedemann,
*Parallel Data, Tools and Interfaces in OPUS*, LREC 2012). 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{hartnett2026gectorda,
  author       = {Hartnett, Patrick Andrew},
  title        = {Proofbird GECToR grammar model (Danish)},
  year         = {2026},
  publisher    = {Hugging Face},
  howpublished = {\url{https://huggingface.co/proofbird/gector-bert-da}},
  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.