From the course: Text Analytics and Predictions with Python Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Recommending next word

Recommending next word - Python Tutorial

From the course: Text Analytics and Predictions with Python Essential Training

Start my 1-month free trial

Recommending next word

- [Instructor] In order to recommend the next word, we build a function called recommend. This function takes a word as input. It then queries the Ngram's database where the first column matches the word passed to the function. If there are multiple matches, the results are sorted in descending order of count. This is so that the bigram with the highest occurrence comes out first. From the records returned, we build a list of next possible words by iterating through the result set. These words are ordered from highest to lowest occurrence since we have already sorted the query in that fashion. We first predict the next word for the word data. Let's run this code block. Looking at the results, the possible next words can be science, analysis and so on. Science occurs the most because the term data science is used in many places in the corpus. This confirms the accuracy of the Ngram's database we built. Next, we predict the next word for science itself. The popular words are begins…

Contents