Ask HN: What is the best method for turning a scanned book as a PDF into text?
I like reading philosophy, particularly from the authors rather than a secondhand account.
However I often run into that these come as scanned documents, Discourses on Livy and Politics Among Nations for example.
I would greatly benefit from turning these into text. I can snipping tool pages and put them in ChatGPT and it turns out perfect. If I used classic methods, it often screws up words. My final goal is to turn these into audiobooks, (or even just make it easier to copypaste for my personal notes)
Given the state of AI, I'm wondering what my options are. I don't mind paying.
121 comments
[ 3.4 ms ] story [ 224 ms ] threadis the simplest thing that might work.
It is free and mature.
OCR is another thing that might work which is also simpler than an LLM.
You can scan a book and listen (also copy and paste the text extracted to other apps).
If you are looking to do this on large scale in your own UI, I would recommend either of Google solutions:
1. Google Cloud Vision API (https://cloud.google.com/vision?hl=en)
2. Using Gemini API OCR capabilities.(Start here: https://aistudio.google.com/prompts/new_chat)
https://github.com/maurycy/gemini-json-ocr
it would be easy to set up a pipeline like:
> drop pdf in s3 bucket > eventbridge triggers step function > sfn calls textract > output saved to s3 & emailed to you
It can correctly read many other languages than English if that is something you need. Previously I tried others and there were many errors in conversion. This does it well.
I'd also tried ocrit, which uses Apple's Vision framework for OCR, with some success - https://github.com/insidegui/ocrit
It's an ongoing, iterative process. I'll watch this thread with interest.
Some recent threads that might be helpful:
* https://news.ycombinator.com/item?id=42443022 - Show HN: Adventures in OCR
* https://news.ycombinator.com/item?id=43045801 - Benchmarking vision-language models on OCR in dynamic video environments - driscoll42 posted some stats from research
* https://news.ycombinator.com/item?id=43043671 - OCR4all
(Meaning, I have these browser tabs open, I haven't fully digested them yet)
I can’t help but think a few amateur humans could have read the pdf with their eyes and written the markdown by hand if the OCR was a little sketchy.
https://news.ycombinator.com/item?id=42952605 - Ingesting PDFs and why Gemini 2.0 changes everything
It seems straightforward except for the canvas strip (I assume this is part of the binding?), and whether you add thicker pages/boards on each side as covers.
Do you have any photos of the process, or at least of a finished product? Thanks!
The original transformer had dense attention where every token attends to every other token, and the computational cost therefore grew quadratically with increased context length. There are other attention patterns than can be used though, such as only attending to recent tokens (sliding window attention), or only having a few global tokens that attend to all the others, or even attending to random tokens, or using combinations of these (e.g. Google's "Big Bird" attention from their Elmo/Bert muppet era).
I don't know what types of attention the SOTA closed source models are using, and they may well be using different techniques, but it'd not be surprising if there was "less attention" to tokens far back in the context. It's not obvious why this would affect a task like doing page-by-page OCR on a long PDF though, since there it's only the most recent page that needs attending to.
Also, PDF size isn’t a relevant measurement of token lengths when it comes to PDFs which can range from a collection of high quality JPEG images to thousand(s) of pages of text
(albeit I believe o3-mini isn't natively multimodal)
(But eg I asked it about something Martin Short / John Mulaney said on SNL and it needed 2 prompts to get the correct answer..... the first answer wasn't making anything up it was just reasonably misinterpreting something)
It also has web search which will be more accurate if the pages it reads are good (it uses bing search, so if possible provide your own links and forcibly enable web search)
Similarly the latest Anthropic Claude Sonnet model (it's the new Sonnet 3.5 as of ~Oct) is very good.
The idea behind o3 mini is that it only knows as much as 4o mini (the names suck, we know) but it will be able to consider its initial response and edit it if it doesn't meet the original prompt's criteria
If you're dealing with public domain material, you can just upload to archive.org. They'll OCR the whole thing and make it available to you and everyone else. (If you got it from archive.org, check the sidebar for the existing OCR files.)
- Original book image: https://imgur.com/a8KxGpY
- OCR from archive.org: https://imgur.com/VUtjiON
- Output from Claude: https://imgur.com/keUyhjR
Note if you're dealing with a work (or edition) that cannot otherwise be found on archive.org, though, then if you do upload it, you are permitted as the owner of that item to open up the OCRed version and edit it. So an alternative workflow might be better stated:
1. upload to archive.org
2. check the OCR results
3. correct a local copy by hand or use a language model to assist if the OCR error rate is too high
4. overwrite the autogenerated OCR results with the copy from step 3 in order to share with others
(For those unaware and wanting to go the collaborative route, there is also the Wikipedia-adjacent WMF project called Wikisource. It has the upside of being more open (at least in theory) than, say, a GitHub repo—since PRs are not required for others to get their changes integrated. One might find, however, it to be less open in practice, since it is inhabited by a fair few wikiassholes of the sort that folks will probably be familiar with from Wikipedia.)
More of a system: AWS Textract or Azure Document Intelligence. This option requires some coding and the cost is higher than using a vision model.