gector-bert-en / README.md
Imperatore's picture
Card: the in-browser demo is retired (coming soon on proofbird.app) - its last mentions removed
1b999f2 verified
|
Raw History Blame Contribute Delete
17.4 kB
metadata
license: apache-2.0
language:
  - en
base_model: google-bert/bert-base-cased
pipeline_tag: token-classification
library_name: onnx
tags:
  - grammatical-error-correction
  - gector
  - onnx
  - on-device
datasets:
  - wikimedia/wikipedia

Proofbird Grammar — English

gector-bert-en · on-device English grammar correction

Try it in your browser: coming soon on proofbird.app.

Version 2.0.0 (the same model and files as 1.2.2, renumbered: the first number now marks the training recipe) · run 2026-11-22-2313 · tag v2.0.0, the files the Proofbird app downloads. Pin it with revision="v2.0.0". Earlier versions stay available under their tags. Versions: a new training recipe or a change to the model's design raises the first number (2 = the recipe of November 2026: a second, spoken corpus beside Wikipedia, targeted training pairs, mostly one error per sentence), a new training run or changed guards, rules or settings the second, card or metadata fixes the third.

A GECToR-style sequence tagger for English grammatical error correction, exported to ONNX (fp32) to run on the CPU. It is the on-device grammar model of Proofbird, 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 verb form), 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-en", "quickstart.py"))
quickstart = importlib.util.module_from_spec(spec)
spec.loader.exec_module(quickstart)

model = quickstart.Gector("proofbird/gector-bert-en")
corrected, suggestions = model.correct("My brother have two cat.")
print(corrected)
print(suggestions)
My brother has two cats.
[{"start": 11, "length": 4, "original": "have", "replacement": "has"}, {"start": 20, "length": 3, "original": "cat", "replacement": "cats"}]

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 "My brother have two cat." prints every step below.

What it corrects

Subject-verb agreement (The results shows → show), tense and participle forms (have went → have gone), a/an, irregular plurals (The mouses ran away → mice, Two knifes → knives), confusables (their/there/they're, your/you're, its/it's, then/than, to/too: I left my keys over their → there, Your very kind → You're), doubled words, capitalisation at the start of a sentence, and everyday-register errors in questions, imperatives and the first and second person (Does the machines work → Do, Opens the window → Open). It finds a single error in a long sentence about as often as in a short one.

It is written for both American and British English: it leaves spelling to the spell checker (colour and color, organise and organize, theatre and theater are all left alone), and with the guards a collective noun keeps a plural verb, as British English allows (The team are playing, The government have announced).

How it was trained

  • Base encoder: google-bert/bert-base-cased (Apache-2.0). A tagging head (990 edit labels) and an error-detection head sit on top.

  • Data: synthetic only. Three sources, 3 250 000 sentences in all:

    • 1 500 000 sentences from English Wikipedia (wikimedia/wikipedia, 20231101.en);
    • 1 500 000 sentences from the proceedings of the European Parliament (Europarl v10, sessions before June 2011): speech in the first and second person, questions and argument, and long sentences, the register encyclopedic text lacks;
    • 250 000 sentences from Tatoeba, everyday English (the sentences held out for the checks below are excluded).

    They were corrupted by hand-written English error rules, mostly one error per sentence whatever its length; about 10% stay clean, so the model learns to leave correct text alone. The rules only replace or double words: none removes a word, so the model does not learn to insert one. Real sentences that carry a pattern the model needs (there as a place, they're and you're before a verb or an adjective, its and it's, than after a comparative, an irregular plural, an imperative) were added again with the error placed exactly there, together with 8 139 template sentences for the shapes the corpora hold too rarely (mice, knives, wolves, they're), and 150 000 further template sentences teach questions, imperatives, the first and second person, group and mass nouns and errors in a later clause.

  • No learner corpora and no non-commercial data of any kind. No user text was used.

  • One epoch (125 863 steps, batch 64, peak learning rate 1.5e-5) on one NVIDIA L4. Run id 2026-11-22-2313; the published weights are the final step.

How it was measured

Check Result
Gold set (420 hand-written sentences: 266 with one error each, 154 correct) 266 fixed, 154 left alone, 0 missed, 0 made worse
Wrong corrections on 4 000 everyday Tatoeba sentences (held out from training) 2 (0.05%). 3 sentences changed: 1 real mistake in the test sentence fixed, 2 wrong
Wrong corrections on 20 000 sentences from European Parliament sessions the model never saw (June 2011 on) 18 (0.09%). 29 sentences changed: 11 real mistakes fixed or equally good alternatives, 18 wrong
One error planted in each of 600 unseen Wikipedia sentences (196 under 20 words, 207 of 20–39, 197 of 40 or more) 92.5% fixed (92.3%, 90.8%, 94.4%)
One error planted in each of 600 unseen European Parliament sentences (199, 203, 198) 90.3% fixed (92.5%, 89.2%, 89.4%)
One error of each trained pattern placed in unseen sentences (418) 97.4% fixed
Stability: the gold re-run with one extra token in front of each sentence (the model alone) 9 of 206 sentences change result (the 4 capitalisation rows change by construction and are not counted)

The scores are with the model's own confidence setting (min_error_prob 0.7 in gector-meta.json: an edit the model is less than 70% 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 266 gold errors and 95.2% / 92.3% of the planted ones, changes 4 correct gold rows, and changes 7 Tatoeba and 64 European Parliament sentences, 5 and 49 of them wrong: it is less sure of its wrong corrections than of its right ones, and the setting uses that. 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. A noun that is also a verb, read as a verb that needs -s (full of rumour → rumours, the restrictive labour market measure adopted by Switzerland → measures, changing Member State while driving → States); agreement changed on a correct sentence, mostly where the subject is far from the verb or looks plural (the majority of 18 Member States was not reached → were, Threads is no different → are, Has what we have done ... → Have).

Known misses. A single planted error is left untouched about 4 times in 100. their for there as a place is the weakest trained pattern (not out their is fixed about 4 times in 5). It does not add a missing word (I had completely forgotten pay the rent is left alone). 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) and are part of every score above. too and then ending a clause are never made to or than (Tom was there too.); persons stays; a word is deleted only when it is written twice, and that that and had had stay; a collective noun keeps a plural verb (The team are, The committee have decided).

Files

File What it is
model.onnx The tagger (fp32, opset 17). Inputs input_ids, attention_mask; outputs logits_labels [1, T, 990] 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.7.
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 (sentence-final punctuation handling).
grammar-messages.json The English card messages: which error each kind of change names (Article, Past participle, Irregular plural, their, there or they're) and a one-line reason. Read by the Proofbird app; the model does not use it.
verb-form-vocab.txt The English verb-form table for the $TRANSFORM_VERB_* tags.
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.

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 990 tags such as $KEEP, $DELETE, $APPEND_are, $REPLACE_an or $TRANSFORM_SUF_ve_s (change a word's ending). quickstart.py does everything around it. This is the real run of the example above.

1. Prepare the text. language-rules.json says the final full stop comes off before the model sees the sentence (it goes back on at the end): My brother have two cat.

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  My  brother  have  two  cat
tokens          [CLS] My brother have two cat [SEP]
input_ids       [101, 1422, 1711, 1138, 1160, 5855, 102]
attention_mask  [1, 1, 1, 1, 1, 1, 1]

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

3. The response. Two outputs (float32): logits_labels [1, 7, 990], a score for each of the 990 edits at every token, and logits_d [1, 7, 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: My brother have two cat

Word Wrong Chosen edit Probability
$START 0.0% $KEEP 100.0%
My 0.0% $KEEP 100.0%
brother 0.0% $KEEP 100.0%
have 100.0% $TRANSFORM_SUF_ve_s 99.9%
two 0.0% $KEEP 100.0%
cat 99.9% $TRANSFORM_SUF__s 75.2%

→ My brother has two cats

Pass 2: My brother has two cats

Word Wrong Chosen edit Probability
$START 0.0% $KEEP 100.0%
My 0.0% $KEEP 100.0%
brother 0.0% $KEEP 100.0%
has 0.0% $KEEP 100.0%
two 0.0% $KEEP 100.0%
cats 0.0% $KEEP 100.0%

→ My brother has two cats — 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.7, 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.7 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.7.

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 English 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", "Article", "Past participle") with a one-line reason from grammar-messages.json, and, on request, a longer explanation.

quickstart.py runs the model on its own, 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). The base encoder is google-bert/bert-base-cased, Apache-2.0. The tagging scheme and verb-form-vocab.txt come from the GECToR project (Omelianchuk et al., 2020, GECToR – Grammatical Error Correction: Tag, Not Rewrite), Apache-2.0.

How to cite

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

@misc{hartnett2026gectoren,
  author       = {Hartnett, Patrick Andrew},
  title        = {Proofbird GECToR grammar model (English)},
  year         = {2026},
  publisher    = {Hugging Face},
  howpublished = {\url{https://huggingface.co/proofbird/gector-bert-en}},
  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.