📎 Webclip
How to Write a Spelling Corrector
The essay shows how to build a compact spelling corrector in Python using Bayes’ theorem, word counts from a training corpus, and candidate words generated by edit distance. It reports decent speed and moderate accuracy, then explains where the simple model fails.
Reading notes#
- The program chooses the most likely correction by combining a language model P(c) with an error model P(w|c).
- The language model comes from counts in a large text file, with smoothing for words not seen in training.
- Candidate corrections are generated from edit distance 1 and 2, then filtered to known words.
- The correction rule prefers the closest known candidates and then picks the one with the highest word frequency.
- Evaluation on development and final test sets gives 74% and 67% accuracy, with faster runtime than a more complex system.
- A bug in the test routine and another issue with defaultdict affected earlier reported results.
- Future improvements include a better language model, a better error model, more distant edits, more context, better data, and faster implementation.
- The essay ends by noting that reaching about 90% accuracy likely requires using surrounding words, not just one word at a time.
