Fixing OCR errors in a legal document with GPT-4
I wanted a searchable text copy of my HOA’s bylaws and condo declaration to send to the other owners, and the only copies I had were scans. Google Docs will OCR a PDF when you open it with Docs, but the text came out full of mistakes like these:
CONDONINlUN DECLARATION
PROTECTION OF NORTGAGEE
shall not e;eed one hundred _and twenty percent (120%) of the monthly
pay any un,~aid Common Expense payable with respect to such Unit,
.~: .. ;.: ........ . ~:. t,.~~: ... ~-
I’d had the paid ChatGPT Plus plan since April for GPT-4, so one night in September I spent a little over two hours pasting the OCR text into it and asking it to clean it up. ChatGPT only took text then, not the scans themselves. GPT-4 can only work with a limited amount of text at once, so I pasted a few pages per message, about 7,000 characters each. Replies longer than about 7,500 characters stopped partway and needed ChatGPT’s “Continue generating” button to finish. This was my first message:
i just uploaded my HOA's bylaws to google docs and attempted to OCR them
there are a bunch of mistakes
can you help me fix them by removing gibberish, unnatural line breaks, make consistent page numbers, and fix OCR mistakes? I also need you to show me your corrections by showing the corrected version next to the old version with a strikethrough
it's important that you don't modify words unless there are mistakes where the OCR translated to the wrong character
i'll be giving you a few pages at a time starting with:
The strikethrough version came back as a table that wouldn’t paste into a document, so I switched to asking for plain text, which left no record of what it changed.
Changes it made anyway
About half of my 40 messages were me correcting its replies. Even with the don’t-modify-words instruction, GPT-4:
- dropped the page numbers from the table of contents, in both the bylaws and the declaration
- summarized, wrote “and so on”, and replaced paragraphs with ellipses
- added an item to the list in the “order of business” section
- rewrote sentences for grammar and clarity
- once wrote new bylaws instead of fixing the text I pasted
It also made up whole clauses at the end of one page of the declaration. My paste stopped at paragraph 8.4 and the page number, and the reply kept going through 8.10:
...
8.9 GENDER AND NUMBER. Whenever the context requires, the singular shall include the plural and the masculine shall include the feminine and the neuter and vice versa.
8.10 ENFORCEMENT. Enforcement of these covenants and restrictions shall be by any proceeding at law or in equity against any person or persons violating or attempting to violate any covenant or restriction, ...
None of 8.5 through 8.10 was in the text I pasted, and it reads like the rest of the declaration, so skimming wouldn’t catch it.
Prompts for the later pages
Asking it to fix a bad reply usually got an apology and only the section I’d complained about. So for most of the declaration I pasted each new batch with the don’t-change-the-text instruction restated, pasted the same pages again when a reply went wrong, and said what the text was for:
here are some more pages i want you to fix for obvious OCR errors without deviating from the original text:
i need the entire text so i can copy it over to another document, remember this is going out to people as a legal document based on the original
It kept shortening and rewriting through the last page, and one of my last messages was “don’t remove anything for brevity!”
Checking it against the scans
The parts I spot-checked looked good, and I put the output together into a markdown version. ChatGPT takes file uploads now, so today I uploaded the scanned PDF along with that markdown and asked it to find mistakes. It treated the scan as an image and couldn’t read it:
The document you've uploaded is in image format (PNG), which means I can't perform a direct text comparison with the markdown version you've provided.
The markdown I uploaded still had changes from September in it. The bylaws end with a list of owners who signed an amendment, and GPT-4 had first left them off “for brevity”. When I asked for the names, it gave me placeholders instead of the names in my paste:
John Doe
Jane Smith
Robert Johnson
...
From paragraph 9.3 on, it had also paraphrased the bylaws into plain English. This is the OCR text I pasted for 9.5(b):
(b) An Owner shall not make structural modifications
or alterations to his Unit or to the installations located
therein without previously notifying the Association in
writing through the President of the Association and
receiving approval from the Board of Directors. The Board
shall have the obligation to answer within thirty (30)
days after such notice. Failure to so answer within the
stipulated time shall mean that there is no objection to
the proposed modification or alteration.
And this is what came back:
(b) Owners must not make structural modifications or alterations to their Units without notifying the Association in writing through the President and receiving approval from the Board of Directors. The Board must respond within 30 days; failure to do so means there's no objection to the proposal.
The OCR text had no errors to fix, and the reply keeps the meaning, but a copy going out to the owners as the bylaws needs their exact wording. ChatGPT can’t read the scans, so checking the rest of the September output against them is a job I’m doing by hand, a page at a time.