Next Word Predictor

Deniz D.

2023-12-23

Next Word Predictor App

The Next Word Predictor app predicts the next word based on the input of the user.

This app is developed for the Capstone Project of the Data Science Specialization. The data for training the model is provided by SwiftKey and is available at:

https://d396qusza40orc.cloudfront.net/dsscapstone/dataset/Coursera-SwiftKey.zip

The Next Word Predictor is an easy to use, simple, light weight and fast Shiny app that takes a text as an input and when the user clicks submit predicts the next word.

Data Processing

  • Only English data sets for News, Twitter and Blogs are used
  • For space saving and performance only 10000 entries from each file is sampled and combined
  • 3-gram, 2- gram and unigram models are created. For space and speed higher order n-grams were not uploaded
  • Bad words, foreign characters, numbers, urls, separators are removed
  • quanteda package is used for tokenization of data and n-gram modeling
  • data.table is used for easy access

Back off Model

When 2 or more words are entered by the user the two words are looked up in the 3-gram, if found the most frequent word that comes next is returned.

If the entered words are not found the second word is looked up in the 2-gram. If it is found the most frequent word that comes next is returned.

If the entered word is not found in the 2-gram than the unigram is sampled and a frequently used word is returned.

In this manner we predict a word by backing off to lower order n-grams.

Shiny App

You can try the app at:

https://denizd.shinyapps.io/WordPrediction/

View the source code at:

https://github.com/DenizDemi/WordPredictor