More on OCRing old code, Google Gemini seems to be excellent

I’m working my way through What To Do After You Hit Return, a project I started a long 7 years ago and never got back to.

For these runs, I experimented with some of the newer free AI models. I found that Google Gemini does a really good job on these listings. It still does some “corrections” like changing # to <>, and sometimes has some whitespace issues, but the results were much better and much faster than Le Chat or GPT the last time I tried this. And so far its only renumbered one program.

And the limit seems endless, I’ve been scanning page after page without hitting any sort of limits!

Now some of this may be due to the printouts being from some a letter-quality printer, as opposed to DEC’s listings in dot-matrix. But on the flip side, the listings are often very skewed, have other bits like page numbers printed right over the code, and are often blurry.

Definitely worth a try if you have some old code.

I’m well over half way through now, have a look!

We’ve used many chatbots for this sort of thing. You’re right that they are very good for general OCR, but when you need exact column alignment, they are mostly unreliable. This is why Rupert Lane built GridLock, which uses LLMs in its workflow.

This is the kind of input I need to OCR.

(This topic and several other previous related ones have the tag ocr )

Scantailor-Advanced is absolutely no use for above/below scans like these. While it gamely tries to perspective-correct the pages, it would need some fiddly page work to crop out the excess background

You definitely need to check out Rupert Lane’s gridlock tool. I’m involved with the IBM 1620 Oregon IPL-V restoration project, and Rupert and gridlock did a fantastic job transcribing the PDF scans.

Lars actually asked Rupert (in email conversation) to try his method, and it doesn’t work as well because what Lars has is poorly-registered photographs, as opposed to well-registered scans. Possibly GridLock could be extended for this. I don’t think we’re every going to be able to get away from this sort of rapid photographic stuff.

This was the best I could do since the owner of the listings considered them fragile and didn’t want to have them do through a “well-registered scanning” process. And there is at least one more of those I want to salvage. I think maybe I could add a pre-processing step that makes the input more amenable to OCR.

1 Like

I get it that you take what you can get. A few suggestions: First, if you’re doing it yourself, use a tripod to get the document well-framed and flat, and adjust the white balance on your camera to enhance the contrast. Second, there are scanner-simulator apps that will try to bring a skewed image back into alignment – imperfect, but way better than just a hand-held photo. (Some of these apps also try to enhance the contrast, but doing that on the input end rather than the backend works better.) Finally, what we did with the Lisp ELIZA when we got the printout from Bernie Cossell was to fan the pages out randomly to the Lisp community who each volunteered to manually enter a couple of pages. I of course can’t speak for others, but I would be more than happy to manually enter a page a day for anyone doing this sort of work. Of course, you actually need two folks for each page in order to flag errors, but maybe combined with AI-based OCR you could get away with one human transcription, then gridlock can do the alignment, if ncessary. There’s a bit of workflow involved but I’ve actually been thinking for some time (since the lisp community thing in … whenver it was, 2015 … worked so well), that it wouldn’t be hard to build a web app that allowed folks like you to submit things for manual processing, and folks like me who are willing to do a page or two a day to get all that “paperwork” done automagicallly.

Old manuscripts like Archimedes Palimpses have been photographed in different colored light, for better contrast.
Would that work here? Ultra violet and Infrared come to mind as a guess.

For me, a large part of the challenge here is that the only scans or photographs available are not excellent in some way. It’s not about how to make a better scan, it’s about how to get a better OCR from an existing image.

I think I have found in the past that some preprocessing can help: whether that be colour balance, flattening to greyscale, sharpening, enlarging, cropping or orientation fixes. But for me the ideal OCR pipeline will look after all that for me.

I have myself done a lot of ‘scanning’ using a handheld mobile phone, in available light. The images that result can have all sorts of problems. So long as the image is in focus (which it once wasn’t) I hope OCR will do a good job.

But of course OCR of typeset English text is one thing, and OCR of printed listings is quite another.

There already is such a web app on https://fromthepage.com/
Here is an example: the SAIL PDP-6 log from 1967.

1 Like

Wow. That’s AWESOME! Unfortunatly, it’s also very expensive once you get beyond the free page limit: $100/month for an individual and $360/month for a group, and I’m guessing that there’s no guarantee that your project will ever get done, and certainly not timely. I had in mind that you have a community, like the lisp community at the time I was doing Cosell’s ELIZA, which was done by, like, ten folks from comp.lang.lisp, who were willing to do it for name credit – or just for fun, as they prefer. Like, for example, I’m willing to promise this community ~one page per day for free. If everyone here did that, and we had our own pretty simple workflow engine it’d cost us nothing and we’d have a clear sense of when you’d get your result. (Of course, I also think that Uber drivers should build their own open-source version of Uber and disintermediate Uber’s profits …which clearly isn’t going to happen, but us socialist democrats can dream.)

Understood. We did exactly that with the PDP-6 ITS listing. Every page was typed independently twice and checked against each other.¹ But for (even more) obscure material like Camexec (above), I believe it’s difficult to raise volunteer interest, or maybe it’s me that feel it’s difficult to ask the favor.


¹ Interestingly, in some cases people made the exact same typo. There’s probably some phycological lesson to be learned from that.

1 Like

You could probably write a whole psych paper about those typos. (The phenomenon is called “familiarity blindness” or, more generally, “inattention blindness”.) You’ve probably seen the famous illusion: https://www.youtube.com/watch?v=IGQmdoK_ZfY