Skip to main content

License: MIT Python 3.11+ PyPI version GitHub release Tests

GreynirCorrect: Spelling and grammar correction for Icelandic

Overview

GreynirCorrect is a Python 3 (>=3.11) package and command line tool for checking and correcting spelling and grammar in Icelandic text.

GreynirCorrect relies on the GreynirEngine package (reynir on PyPI), by the same authors, to tokenize and parse text. Each version of GreynirCorrect works with one minor version of GreynirEngine, as its grammar checks depend on the shape of the parse trees: version 4.3 requires GreynirEngine 4.2.

GreynirCorrect is documented in detail here.

The software has three main modes of operation, described below. All three can be used from several threads at once, also on free-threaded Python (see Use in threads).

Token-level correction

GreynirCorrect can tokenize text and return an automatically corrected token stream. This catches token-level errors, such as spelling errors and erroneous phrases, but not grammatical errors. Token-level correction is relatively fast.

Full grammar analysis

GreynirCorrect can analyze text grammatically by attempting to parse it, after token-level correction. The parsing is done according to Greynir's context-free grammar for Icelandic, augmented with additional production rules for common grammatical errors. The analysis returns a set of annotations (errors and suggestions) that apply to spans (consecutive tokens) within sentences in the resulting token list. Full grammar analysis is considerably slower than token-level correction.

Command-line tool

GreynirCorrect can be invoked as a command-line tool to perform token-level correction and, optionally, grammar analysis. The command is correct infile.txt outfile.txt. The command-line tool is further documented below.

Examples

To perform token-level correction from Python code:

from reynir_correct import tokenize
g = tokenize("Af gefnu tilefni fékk fékk daninn vilja sýnum "
    "framgengt í auknu mæli.")
for tok in g:
    if tok.txt:
        print("{0:10} {1}".format(tok.txt, tok.error_description).rstrip())

Output:

Að         Orðasambandið 'Af gefnu tilefni' var leiðrétt í 'Að gefnu tilefni'
gefnu
tilefni
fékk       Endurtekið orð ('fékk') ætti að fella burt
Daninn     Orð á að byrja á hástaf: 'daninn'
vilja      Orðasambandið 'vilja sýnum framgengt' var leiðrétt í 'vilja sínum framgengt'
sínum      Rita á 'sýnum' sem 'sínum'
framgengt
í          Orðasambandið 'í auknu mæli' var leiðrétt í 'í auknum mæli'
auknum     Rita á 'auknu' sem 'auknum'
mæli
.

To perform full spelling and grammar analysis of a sentence from Python code:

from reynir_correct import check_single
sent = check_single("Páli, vini mínum, langaði að horfa á sjónnvarpið.")
for annotation in sent.annotations:
    print("{0}".format(annotation))

Output:

000-004: P_WRONG_CASE_þgf_þf  Á líklega að vera 'Pál, vin minn,' | 'Páli, vini mínum,' -> 'Pál, vin minn,'
009-009: S004                 Orðið 'sjónnvarpið' var leiðrétt í 'sjónvarpið' | 'sjónnvarpið' -> 'sjónvarpið'

The annotation.start and annotation.end properties (here start is 0 and end is 4) contain the 0-based indices of the first and last tokens to which the annotation applies. annotation.code is the error code (here P_WRONG_CASE_þgf_þf and S004), annotation.text a description of the error, annotation.detail a longer explanation where there is one, and annotation.suggest the suggested replacement for the tokens.

The text of the sentence with the token-level corrections applied, but not the suggestions of the grammar annotations, is in sent.tidy_text:

sent.tidy_text

Output:

'Páli, vini mínum, langaði að horfa á sjónvarpið.'

For more detailed, low-level control, the check_errors() function supports options and can produce various types of output:

from reynir_correct import check_errors
x = "Páli, vini mínum, langaði að horfa á sjónnvarpið."
options = { "input": x, "annotations": True, "format": "text" }
s = check_errors(**options)
print(s)

Output:

Pál, vin minn, langaði að horfa á sjónvarpið.
009-009: S004                 Orðið 'sjónnvarpið' var leiðrétt í 'sjónvarpið' | 'sjónnvarpið' -> 'sjónvarpið'
000-004: P_WRONG_CASE_þgf_þf  Á líklega að vera 'Pál, vin minn,' | 'Páli, vini mínum,' -> 'Pál, vin minn,'

The first line is the text with both the token-level corrections and the suggestions of the annotations applied.

The following options can be specified:

Option Description Default value
input The text to check: a string or an iterable of strings, such as a file object. (required)
format The format of the output: text, json, csv or m2 (the M2 format of grammatical error correction). json
all_errors Defines the level of correction. If False, only token-level annotation is carried out. If True, sentence-level annotation is carried out. True
annotations If True, the annotations are listed after the text. Applies to the text format. False
generate_suggestion_list If True, annotations can in certain cases contain a list of possible corrections, for the user to pick from. False
suppress_suggestions If True, more farfetched automatically suggested corrections are suppressed. False
suggest_not_correct If True, some stylistic errors are presented as suggestions only, and the text is not changed. False
ignore_wordlist The value is a set of strings to whitelist. Each string is a word that should not be marked as an error or corrected. The comparison is case-sensitive. set()
ignore_rules A set of error codes that should be ignored in the annotation process. set()
tov_config Path to an additional configuration file that may be provided for correcting custom tone-of-voice issues. None
flesch If True, a Flesch readability score for the text is added to the output. False
rare_words If True, a list of the rare words in the text is added to the output. False

An overview of error codes is available here.

To check many texts with the same options, create a GreynirCorrectAPI object once and call its correct() method for each text. from_options() takes the options of check_errors() that concern how the text is checked; ignore_rules and suppress_suggestions are arguments of correct():

from reynir_correct import GreynirCorrectAPI
api = GreynirCorrectAPI.from_options()
result = api.correct("Hún fór heim til sýn.")
for sent in result.sentences:
    print(sent.corrected_str(apply_annotations=True))
    for annotation in sent.annotations:
        print(annotation.code, annotation.text)

Output:

Hún fór heim til sýnar.
P_NT_FsMeðFallstjórn Á sennilega að vera 'sýnar'

Use in threads

From version 4.3.1, GreynirCorrect can be used from several threads at once. This applies to the functions (tokenize(), check_single(), check(), check_errors()) and to a GreynirCorrectAPI or GreynirCorrect object that the threads share. The results are the same as from a single thread.

from concurrent.futures import ThreadPoolExecutor
from reynir_correct import GreynirCorrectAPI

api = GreynirCorrectAPI.from_options()
texts = [
    "Páli, vini mínum, langaði að horfa á sjónnvarpið.",
    "Hún fór heim til sýn.",
    "Hundurinn beit manninn í gær.",
]
with ThreadPoolExecutor(max_workers=3) as pool:
    for result in pool.map(api.correct, texts):
        for sent in result.sentences:
            print([annotation.code for annotation in sent.annotations])

Output:

['P_WRONG_CASE_þgf_þf', 'S004']
['P_NT_FsMeðFallstjórn']
[]

In version 4.3.0 and older, such an object could not be shared: a call from a second thread could fail with ValueError: DefaultPipeline.tokenize() is not re-entrant. With those versions, give each thread an object of its own.

On free-threaded Python (3.14t and newer), the threads run in parallel, and the GIL stays off when the package is imported. On a machine where 16 processes check news text 6.4 times as fast as one process, 16 threads check it 5.1 times as fast as one thread (and 8 threads 4.3 times as fast). Each thread there has its own object for the Icegrams trigram model, which costs a few megabytes per thread; the model itself is a memory-mapped file that the threads share. Tools that add up the resident memory of each mapping show more than is in use.

With the GIL, threads are safe but not faster than one thread, and many threads are slower. To use more cores there, use processes.

Prerequisites

GreynirCorrect runs on CPython 3.11 or newer, including free-threaded CPython (3.14t and newer), and on PyPy 3.11 or newer. It is tested on Linux, macOS and Windows.

GreynirCorrect itself is pure Python. Two of the packages that it depends on, GreynirEngine and Icegrams, contain compiled code and have binary wheels on PyPI for common environments. Where there is no wheel for your environment, they are built from source when installed, which needs a C++ compiler and the Python development headers, for instance:

sudo apt-get install build-essential python3-dev

Installation

To install this package (assuming you have Python >= 3.11 with pip installed):

pip install reynir-correct

GreynirCorrect uses the trigram model of the Icegrams package for spelling correction. Icegrams 2.2 and newer gets the model from the icegrams-data package, which is installed along with it, so there is nothing more to do.

With Icegrams 2.0 or 2.1, the model is not installed with the package, and must be downloaded once:

python -m icegrams.download

If the model is missing, GreynirCorrect raises ModelNotFoundError on first use, with these same instructions. See the Icegrams documentation for how to keep the model elsewhere via the ICEGRAMS_MODEL_FILE environment variable.

If you want to be able to edit the source, do like so (assuming you have git installed):

git clone https://github.com/mideind/GreynirCorrect
cd GreynirCorrect
# [ Activate your virtualenv here if you have one ]
pip install -e ".[dev]"

The package source code is now in GreynirCorrect/src/reynir_correct. See Development and tests below for a setup with uv.

The command line tool

After installation, the corrector can be invoked directly from the command line:

correct input.txt output.txt

...or:

$ echo "Þinngið samþikkti tilöguna" | correct
Þingið samþykkti tillöguna

Input and output files are encoded in UTF-8. If the files are not given explicitly, stdin and stdout are used for input and output, respectively.

Empty lines in the input are treated as sentence boundaries.

By default, the output is the corrected text, one sentence per line, with quotation marks and other punctuation in their Icelandic form.

The following options can be specified on the command line:

Option Description
--format FORMAT, -f The format of the output: text (the default), csv, json or m2.
--csv, -c The same as --format csv: token objects in CSV format, one per line.
--json, -j The same as --format json: token objects in JSON format, one per line.
--grammar, -g Check grammar as well as spelling, and output whole-sentence annotations, including corrections and suggestions. Each sentence in the input is output as a text line containing a JSON object, terminated by a newline.
--all_errors, -a Check grammar as well as spelling, and keep the chosen output format.
--spaced, -sp Separate the tokens of the output with spaces, and leave punctuation as it is in the input.
--normalize, -n With --spaced: normalize punctuation, causing e.g. quotes to be output in Icelandic form.
--suppress_suggestions, -ss Suppress the more farfetched suggestions.
--suggest_not_correct Present some stylistic errors as suggestions only, without changing the text.
--flesch Add a Flesch readability score for the text to the output.
--rare_words Add a list of the rare words in the text to the output.
--tov_config FILE An additional configuration file with rules for custom tone-of-voice issues, in the format of GreynirCorrect.conf.
--sentence_prefilter Run a classifier on each sentence first, and only parse those that probably have an error. This needs the sentence_classifier extra (pip install "reynir-correct[sentence_classifier]"), which is not available for PyPy.

In the CSV and JSON formats of token objects, each token has its kind and text as documented for the Tokenizer package, followed by the error that was found in it, if any.

The JSON format of whole-sentence annotations is shown in the last of the examples below.

Type correct -h to get a short help message.

Command Line Examples

$ echo "Atvinuleysi jógst um 3%" | correct
Atvinnuleysi jókst um 3%
$ echo "Barnið vil grænann lit" | correct --csv
6,"Barnið","",""
6,"vil","",""
6,"grænan","","S004: Orðið 'grænann' var leiðrétt í 'grænan' | grænann->grænan"
6,"lit","",""

Note how vil is not corrected, as it is a valid and common word, and the correct command does not perform grammar checking by default.

$ echo "Pakkin er fyrir hestin" | correct --json
{"k":"WORD","t":"Pakkinn","e":{"code":"S004","descr":"Orðið 'Pakkin' var leiðrétt í 'Pakkinn'"}}
{"k":"WORD","t":"er"}
{"k":"WORD","t":"fyrir"}
{"k":"WORD","t":"hestinn","e":{"code":"S004","descr":"Orðið 'hestin' var leiðrétt í 'hestinn'"}}

To perform whole-sentence grammar checking and annotation as well as spell checking, use the --grammar option:

$ echo "Ég kláraði verkefnið þrátt fyrir að ég var þreittur." | correct --grammar
{
   "original":"Ég kláraði verkefnið þrátt fyrir að ég var þreittur.",
   "corrected":"Ég kláraði verkefnið þrátt fyrir að ég væri þreyttur.",
   "tokens":[
      {"k":6,"x":"Ég","o":"Ég","i":0},
      {"k":6,"x":"kláraði","o":" kláraði","i":2},
      {"k":6,"x":"verkefnið","o":" verkefnið","i":10},
      {"k":6,"x":"þrátt fyrir","o":" þrátt fyrir","i":20},
      {"k":6,"x":"að","o":" að","i":32},
      {"k":6,"x":"ég","o":" ég","i":35},
      {"k":6,"x":"væri","o":" var","i":38},
      {"k":6,"x":"þreyttur","o":" þreittur","i":42},
      {"k":1,"x":".","o":".","i":51}
   ],
   "annotations":[
      {
         "start":6,
         "end":6,
         "start_char":38,
         "end_char":41,
         "code":"P_MOOD_ACK",
         "text":"Hér er réttara að nota viðtengingarhátt sagnarinnar 'vera', þ.e. 'væri'.",
         "detail":"Í viðurkenningarsetningum á borð við 'Z' í dæminu 'X gerði Y þrátt fyrir að Z' á sögnin að vera í viðtengingarhætti fremur en framsöguhætti.",
         "suggest":"væri"
      },
      {
         "start":7,
         "end":7,
         "start_char":42,
         "end_char":50,
         "code":"EI4EY",
         "text":"Stafsetningarvilla: 'þreittur' -> 'þreyttur'",
         "detail":"Rita ætti 'ey' í stað 'ei' í 'þreittur', svo: 'þreyttur'.",
         "suggest":"þreyttur"
      }
   ]
}

The output has been formatted for legibility - each input sentence is actually represented by a JSON object in a single line of text, terminated by newline.

In each token, x is the corrected text, o the original text with the whitespace in front of it, and i the index in the input where o starts. In each annotation, start and end are the indices of the first and last tokens that it applies to, and start_char and end_char the indices in the input of the first and last characters of those tokens' original text.

The corrected field has the sentence with the token-level corrections and the suggestions of the annotations applied (in this case þreittur -> þreyttur and var -> væri). To apply only some of them, replace source text or tokens (as identified by the start and end, or start_char and end_char properties) with the suggest field, if present.

Development and tests

The repository has a uv.lock file, so uv sets up an environment with the versions of the dependencies that the tests are run with on GitHub. In your GreynirCorrect directory:

uv sync
uv run pytest
uv run ruff check src/reynir_correct
uv run mypy src/reynir_correct

Without uv, install the package with its development dependencies (pip install -e ".[dev]", optionally in a virtualenv) and run python -m pytest.

On free-threaded Python, the tests are also run with each test in 8 threads at once:

uv run --python 3.14t pytest --parallel-threads=8

The tests run on GitHub for every pull request: on CPython 3.11 to 3.15, free-threaded CPython 3.14t and 3.15t and PyPy 3.11 on Linux, and on CPython 3.13 on Windows and macOS. A release is made by pushing a version tag: the wheel is then built, checked on Linux, macOS and Windows, and published to PyPI.

Acknowledgements

Parts of this software are developed under the auspices of the Icelandic Government's 5-year Language Technology Programme for Icelandic, which is managed by Almannarómur and described here (English version here).

Miðeind ehf.

Copyright © 2018-2026 Miðeind ehf.

GreynirCorrect's original author is Vilhjálmur Þorsteinsson.

This software is licensed under the MIT License:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


GreynirCorrect indirectly embeds the Database of Icelandic Morphology (Beygingarlýsing íslensks nútímamáls) along with directly using Ritmyndir, a collection of non-standard word forms. Miðeind does not claim any endorsement by the BÍN authors or copyright holders.

The BÍN source data are publicly available under the CC BY-SA 4.0 license, as further detailed here in English and here in Icelandic.

In accordance with the BÍN license terms, credit is hereby given as follows:

Beygingarlýsing íslensks nútímamáls. Stofnun Árna Magnússonar í íslenskum fræðum. Höfundur og ritstjóri Kristín Bjarnadóttir.

Metadata

Release files for reynir-correct 4.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reynir-correct 4.3.1
File Size Uploaded Provenance Actions
reynir_correct-4.3.1.tar.gz 3.9 MB With provenance Details for reynir_correct-4.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for reynir-correct 4.3.1
File Interpreter ABI Platform Actions
reynir_correct-4.3.1-py3-none-any.whl Python 3 none any Details for reynir_correct-4.3.1-py3-none-any.whl

Total release size: 7.7 MB

Release files / reynir_correct-4.3.1.tar.gz

Download URL reynir_correct-4.3.1.tar.gz
Size 3.9 MB
Tags Source
SHA-256 checksum
How to use checksums
407a96752cd87c4219d46ccbe4c12f8b690155f38332c03880fd5c0a31831e8f
BLAKE2b-256 checksum
How to use checksums
8d7d7fad89021d6c104ec3b69a99950d6568a6d7d0d76f4b7c18ecaea8024052
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / reynir_correct-4.3.1-py3-none-any.whl

Download URL reynir_correct-4.3.1-py3-none-any.whl
Size 3.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
c002d2c23b6d908df496bc29bbfed0ff461421f5bfa645194c64b1a562d8798f
BLAKE2b-256 checksum
How to use checksums
34bc94f17f4178789fbc3b3f2aaf63078499e98b99592337b2bca2a384344066
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for reynir-correct 4.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for reynir_correct-4.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page