Correcting spelling errors in OCR texts Situation

*

*customer contracts available as scanned images were turned into text files using OCR software

*the resulting texts contain spelling errors that occurred during OCR, e.g. words like "useful" were mistaken as "u5eful"

Question
What are current best practices for correcting these OCR spelling errors as a post-processing step?

*

*for standard vocabularies, i.e. correcting common words

*for specific vocabularies, i.e. correcting specific product names, customer names, special terms etc.

Thanks!
 A: The best solution would probably be to re-OCR the documents using a better OCR, ideally with a language model that is specifically tuned for the domain of the documents.
Otherwise, you can use a spell-checker with an additional custom vocabulary, there are several Python packages for that, e.g., pyspelling has an interface for both Hunspell and Aspell. The advantage of existing spell-checkers is that they have optimized algorithms for retrieving correct similar words. The disadvantage is that they treat all edits equally.
To get around this, you can get more spell-checker suggestions than you would normally display to a user and re-score them. The simplest way is designing a weighted edit distance where errors that are frequent in your data would get a low cost (e.g., substituting s and 5 should be a cheap operation). There are also several Python packages for that, weighted-levenshtein should be pretty fast. If you want a really fancy solution, you can re-score the suggestions using a language model.
