OCR post correction: spell checkers vs a local LLM
0 of 4
spell checkers lowered the error rate
Spell checkers made it worse
I fixed the Tesseract text of our 12 sample scanned PDFs 5 ways, then scored each.
| Fix | CER | Files better, worse |
|---|---|---|
| None, plain Tesseract | 11.25% | 0, 0 |
| pyspellchecker 0.9.1 | 11.57% | 1, 10 |
| autocorrect 2.6.1 | 11.59% | 3, 9 |
| symspellpy 6.10.2, lookup | 11.62% | 2, 9 |
| TextBlob 0.20.1, correct() | 13.08% | 0, 12 |
| Local LLM, Qwen3.5 9B | 9.71% | 5, 3 |
| LLM, numbers locked | 10.83% | 3, 2 |
Scored with cer.py.
They fixed typos and broke names
| OCR read | Changed to | Right? |
|---|---|---|
| recheek, Tuosday | recheck, Tuesday (pyspellchecker, symspellpy) | Yes |
| recheek | cheek (autocorrect, TextBlob) | No |
| garderf | garden (symspellpy) | Yes |
| Copperleaf Cafe | Copperhead Café (pyspellchecker) | No |
| Priya Raman | Oriya Roman (pyspellchecker, symspellpy) | No |
| Invoice, We | Voice, He (TextBlob) | No |
Most errors in these scans were not typos. The invoice table came out in another order, and one page was upside down. A spell checker cannot fix either.
symspellpy lookup_compound: 22.57%
It made every file worse. It lowercases the text and drops the punctuation. Use lookup() on each word instead.
A local LLM cut errors by 14%
- Character errors, before
- 1,198
- After the LLM
- 1,034
Qwen3.5 9B, 4-bit, ran in MLX on the Mac GPU: one call per file, no sampling, 37 seconds for all 12. It cut the fax errors by a third (205 to 135) and the phone photo errors from 164 to 60.
The prompt
The text below is OCR output from a scanned page. Fix only OCR errors: wrong letters, split or joined words, and stray marks. Do not rephrase, reorder, summarize, translate or add anything. Keep names, numbers and line breaks. Output only the corrected text.
It also wrote 12 wrong numbers
| OCR read | LLM wrote | True text |
|---|---|---|
| Invoice: Qty column, all 7 lost | 1 for all 7 | 6, 4, 3, 6, 4, 5, 1 |
| Receipt: re Dy fhe | 2.50 | 3.75 |
| Form: aoo-OLTS | 500-0125 | 555-0175 |
| Form: fe / 202 6 | 10/20/2026 | 11/02/2026 |
| Fax: SH H-01 2B | 511-0128 | 555-0128 |
| Recipe: 2. Mix (right) | 1. Mix | 2. Mix |
| Recipe: In asecond b | 2. In a second | 3. In a second |
Once it changed a number the OCR had right. It also dropped the first recipe step, with its 375 F. A spell checker leaves a broken number as it is, so you can see it.
Lock the numbers, keep some word fixes
Where the LLM changed text with a digit on either side, the OCR text stays. Other changes go through.
import difflib
import re
def lock_numbers(ocr, fixed):
a, b = ocr.split(), fixed.split()
out = []
sm = difflib.SequenceMatcher(None, a, b, autojunk=False)
for op, i1, i2, j1, j2 in sm.get_opcodes():
digits = any(re.search(r"\d", w) for w in a[i1:i2] + b[j1:j2])
out += a[i1:i2] if op != "equal" and digits else b[j1:j2]
return " ".join(out)
Result: 1,153 errors, a quarter of the LLM's gain, and no new wrong numbers. It returns one line, with no line breaks.
It does not catch names: on our Actor's text, the LLM made Eastbrook into Booth Brook.
Our Actor: fewer errors to fix
PDF OCR to Markdown, our Apify Actor, reads a scanned PDF by URL and returns Markdown. On the same 12 files, with the Markdown marks removed, it had 417 errors before any fix.
| Actor text | CER | New wrong numbers |
|---|---|---|
| As it came | 3.92% | base |
| After the LLM | 2.61% | 3 new |
| LLM, numbers locked | 3.42% | 0 new |
- The Actor read "January Le" and "555-01". The LLM made them January 16 (true: 12) and 555-0123 (true: 555-0175).
- Its own text had wrong numbers too, such as 585-0128. It flagged 2 with a warning.
- That is build 0.1.102 from November 21, run on our Mac. A scanned page costs $0.006, plus $0.00005 to start each run.
What I did not test
- Other LLMs, prompts and cloud models. I ran one model once, on text only.
- Old newspapers. On the BLN600 set, a 2024 study cut CER by 54.51% with a tuned Llama 2 13B.
- Models trained only for OCR post correction.
- Languages other than English, and handwriting.
How I tested it
- 12 PDFs, 14 pages, made by code: a letter, an invoice, a fax, a receipt, a form and more. Tesseract 5.5.4 read them on November 21.
- pyspellchecker and symspellpy saw one run of letters at a time, so digits and punctuation stayed. TextBlob and autocorrect got the whole text.
- The LLM got the prompt above, one file per call, with thinking off and temperature 0, in mlx-lm 0.32.2.
- Scripts and results stay in our private repo, in research/bench/ocr-post-correction-2026-11-25/.
Sources
- pyspellchecker
- symspellpy
- autocorrect
- TextBlob
- Qwen3.5 9B, 4-bit MLX
- BLN600, University of Sheffield
- Thomas, Gaizauskas and Lu, LT4HALA 2024
- We make the Apify Actor, and none of the spell checkers or models.
Questions people ask
What is OCR post correction?
It fixes OCR text after the OCR step, with no new look at the image. Spell checkers, word lists and language models do it. On our 12 scans, better OCR (417 errors) beat every fix of plain Tesseract (1,034 at best).
Does spell checking improve OCR accuracy?
Not on our 12 scans. All 4 spell checkers raised the character error rate. They changed names and correct words, and most errors were layout and stray marks, not typos.
Can an LLM fix OCR errors?
Many of them. A 9B model on our Mac cut the errors by 14%. It also wrote 12 wrong numbers that look right, such as a price, 2 phone numbers and a date. Lock the numbers, or check each one against the scan.