Show HN: LLM-aided OCR – Correcting Tesseract OCR errors with LLMs (opens in a new tab)github.com
479 pointsWell, it's amazing how things have changed since then. Not only have models gotten a lot better, but the latest "low tier" offerings from OpenAI (GPT4o-mini) and Anthropic (Claude3-Haiku) are incredibly cheap and incredibly fast. So cheap and fast, in fact, that you can now break the document up into little chunks and submit them to the API concurrently (where each chunk can go through a multi-stage process, in which the output of the first stage is passed into another prompt for the next stage) and assemble it all in a shockingly short amount of time, and for basically a rounding error in terms of cost.
My original project had all sorts of complex stuff for detecting hallucinations and incorrect, spurious additions to the text (like "Here is the corrected text" preambles). But the newer models are already good enough to eliminate most of that stuff. And you can get very impressive results with the multi-stage approach. In this case, the first pass asks it to correct OCR errors and to remove line breaks in the middle of a word and things like that. The next stage takes that as the input and asks the model to do things like reformat the text using markdown, to suppress page numbers and repeated page headers, etc. Anyway, I think the samples (which take less than 1-2 minutes to generate) show the power of the approach:
Original PDF:
https://github.com/Dicklesworthstone/llm_aided_ocr/blob/main...
Raw OCR Output:
https://github.com/Dicklesworthstone/llm_aided_ocr/blob/main...
LLM-Corrected Markdown Output:
https://github.com/Dicklesworthstone/llm_aided_ocr/blob/main...
One interesting thing I found was that almost all my attempts to fix/improve things using "classical" methods like regex and other rule based things made everything worse and more brittle, and the real improvements came from adjusting the prompts to make things clearer for the model, and not asking the model to do too much in a single pass (like fixing OCR mistakes AND converting to markdown format).
Anyway, this project is very handy if you have some old scanned books you want to read from Archive.org or Google Books on a Kindle or other ereader device and want things to be re-flowable and clear. It's still not perfect, but I bet within the next year the models will improve even more that it will get closer to 100%. Hope you like it!
[0] https://news.ycombinator.com/item?id=36976333
Comments (172) 48 threads
Show all comments
Showing thread 6 of 48
One of the benefits of this project is that it doesn’t seem to matter that much that there are mistakes in the OCR output as long as you’re dealing with words, where the meaning would be clear to a smart human trying to make sense of it and knowing that there are probable OCR errors. For numbers it’s another story, though.
So you don't have to assume: I gave up after running on 8 cores (Ryzen 7 2700) for 10 days for a single page.
Even worse for my uses, Tesseract had two mistakes on this page (part of why I picked it), and neither of them were correctly read by EasyOCR.
Partial list of mistakes:
1. Missed several full-stops at the end of sentences
2. Rendered two full-stops as colons
3. Rendered two commas as semicolons
4. Misrendered every single em-dash in various ways (e.g. "\_~")
5. Missed 4 double-quotes
6. Missed 3 apostrophes, including rendering "I'll" as "Il"
7. All 5 exclamation points were rendered as a lowercase-ell ("l"). Tesseract got 4 correct and missed one.
https://apps.apple.com/us/app/super-pdf-ocr/id6479674248
Continue this thread — 3 replies
Continue this thread — 7 replies
For our use case PaddleOCR + LLM has been quite nice combo.
I did more or less the same, trying to solve the same problem. I ended up biting the bullet and using Amazon Textract. The OCR is much better than Tesseract, and the layout tool is quite reliable to get linear text out of 2-columns documents (which is critical for my use case).
I would be very happy to find something as reliable that would work on a workstation without relying on anyone’s cloud.