On this page

A result can read smoothly and still hold words that are not on the page. A language model that reads a page writes the most likely next word; when the page is unclear, the most likely word is not always the word on the page. On 300 public pages, an image-to-text model wrote text that is not on the page in 17 of 100 pages of one source type; a second, CTC-based OCR engine (it reads each text line as characters at fixed positions) adds a box and a flag to every word.

OCR hallucination: what it means when a language model reads a page

Classic OCR reads a picture of a word and writes down what it sees. A language model that reads documents does something else: it writes text one piece after another, and each piece is the most probable continuation of what it wrote before. That works well on clean pages. On a page with formulas, a chart, a stamp or a coffee stain it has two jobs at once, reading and guessing, and the output looks the same either way.

The result reads smoothly. A wrong word and a right word look alike. That is what makes it hard to find later.

OCR hallucination rate: invented text counted on 300 pages

An image-to-text language model read 300 public pages from three kinds of source, 100 pages each: arXiv-style papers, German parliamentary papers and US government pages, with one model and one prompt. Its output was compared with the text layer of each PDF and with the CTC OCR engine, and the text it wrote that is not on the page was counted.

Text pieces the image-to-text model wrote that match nothing in the reference, 100 pages per source: 102 on arXiv-style pages, 0 on parliamentary papers, 0 on US government pages.

Text pieces the model wrote that match nothing in the reference. Test on 300 public pages, 100 from each of three sources.

Source (100 pages each) Loop or cut off Inserted pieces Pages with inserted pieces Lines dropped, confirmed by words
arXiv-style papers 3 102 17 85
German parliament papers 0 0 0 0
US government pages 0 0 0 10

On two of three sources the model wrote nothing that was not there. On the third, which is dense with formulas, tables and plots, 17 of 100 pages carried invented text, and 3 pages ran into an endless loop or were cut off. Over all 300 pages the model also lost lines: 240 of 12,728 reference lines (1.9 %), of which 95 (0.75 %) are confirmed by a word comparison.

So the problem sits on the pages an archive is most likely to hold a few of: figures, tables, stamps, bad scans.

Why a model confidence score misses OCR hallucination

The obvious idea is to look at how sure the model is about each word and flag the unsure ones. The median word probability on pages with inserted text was 0.9926. On pages without it, 0.9957. The two numbers are almost the same. A model that is about to invent something is not less sure than one that is reading.

Pages Median word probability
with inserted text 0.9926
without 0.9957

That is why a threshold on the model's own confidence is a weak alarm. A second opinion with a different way of failing is the alternative, described in the next sections.

How a CTC OCR engine avoids hallucination: every word has a box on the page

A CTC OCR engine (connectionist temporal classification) first finds the lines of text on the page, cuts each one out as a small image, and outputs characters aligned to positions along that image. It reads each line image on its own; there is no earlier output to continue. The pipeline description marks this in its description as autoregressive: false.

That gives three properties that matter here:

  • No text without a place. Every word it returns sits on a box on the page. Text with no place on the page cannot appear.
  • No loop. It has no next-word loop to fall into, so a page it cannot read cannot send it running.
  • A confidence per word that comes from the picture, not from the sentence.

It can still misread a word, and every word it writes comes from the image of its line.

Combining a language model with a CTC OCR engine: word boxes and flags

The language model's text stays as written; the CTC OCR engine places and checks every word. For each word the result carries a box, a confidence, and where they disagree, a flag:

  • differs: the CTC OCR engine reads this word differently.
  • punct_differs: the same word, different punctuation.
  • low_conf: the CTC OCR engine is unsure about this word.
  • no_ctc: no box was found for this word.

That merge ran offline on 20 pages with 4,406 words. 99.4 % of the words received a CTC box. The merge changed the text of 0 blocks. It raised 65 differs, 98 punct_differs and 17 low_conf flags, so a reviewer looks at a short list instead of every page.

Outlines of the word boxes found on one test page; blue for words confirmed by the CTC OCR engine, red for words flagged.

One test page, merged. Blue boxes: words with a CTC box and no flag (119). Red boxes: flagged words (differs 5, low_conf 2, no_ctc 1). The page text is not shown, only where each word sits. Run offline-2.

This is the shape of the merged pipeline: the language model reads, the CTC OCR engine confirms and locates, and the flag says where a person should look. Status of the merged pipeline: measured in an offline run. The CTC OCR engine on its own is built and tested as a pipeline.

How to detect OCR hallucination in your own LLM or RAG pipeline

  • Ask for a box per word and plot them on the page. Words with no place on the page are the first suspects.
  • Run two OCR engines that fail differently on a sample and diff them. Disagreements are a review list.
  • Pair the model's own probability with a second reading. In the 300-page run the probability was almost equal with and without inserted text.

History of OCR: from templates and CTC to page-reading models

OCR is old, and each step solved the one before.

  • Templates, 1913 to 2005. The optophone (1913) turned printed letters into sounds. Tauschek patented a template-matching reading machine in 1929. A Kurzweil machine read ordinary fonts aloud in 1976. Tesseract became open source in 2005. Templates only fit the fonts they were made for.
  • Networks read lines, 2006 to 2015. CTC (2006) lets a network learn whole lines without marking every letter. By 2015 one network read a whole line image. A line reader sees one line at a time.
  • Models read pages, 2023 on. Models that read page images see the whole page, but sometimes write text that is not there.

Sources for the history: (History of OCR on Wikipedia; 2006: Graves and others, ICML; 2015: Shi, Bai and Yao, arXiv).

Sources

Statement Where it comes from
3 of 100 loops or cut off, 102 inserted pieces on 17 pages, 0 on the other two sources, 85 and 10 confirmed dropped lines test on 300 public pages from three sources (arXiv-style papers, German parliament papers, US government pages), summary of 4 Nov 2026
240 of 12,728 lines, 95 confirmed (0.75 %) same run, all 300 pages
median probability 0.9926 against 0.9957 same run, pages with and without an inserted piece
4,406 words, 99.4 % with a box, 0 blocks changed, 65, 98, 17 flags merge run offline-2, 20 public pages, CPU only
box figure: 119 plain, 5, 2, 1 flagged merge run offline-2, one hard test page
18 number words without a text-layer match merge run offline-2
73 CTC text pieces without a text-layer match same 300-page run, CTC OCR engine