Sitemap
The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

Follow publication

Member-only story

How to Build an Autocorrect in Python

3 min readOct 1, 2020

--

Image by Author

Description

We assume that you are familiar with the concepts of String Distance and String Similarities. You can also have a look at the Spelling Recommender. We will show how you can easily build a simple Autocorrect tool in Python with a few lines of code. What you will need is a corpus to build your vocabulary and the word frequencies. The idea is the following:

  • You enter a word, if this is word exists in the vocabulary then we assume that is correct.
  • If this word does not exist in the vocabulary we try to find the most similar words ordered by their frequency probability.

Build the Vocabulary

We will work with the Moby Dick book. Let’s start.

import pandas as pd
import numpy as np
import textdistance
import re
from collections import Counter
words = []

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

George Pipis
George Pipis

Written by George Pipis

Sr. Director, Data Scientist @ Persado | Co-founder of the Data Science blog: https://predictivehacks.com/