JHU Data Science Capstone

Aaron S

Predict the Next Word(s)! App Introduction

This presentation features the Predict the Next Word(s)! app, including an introduction to the application user interface and details about the text prediction algorithm.

The shiny app is located at: https://questonr.shinyapps.io/word-predict/

Check back regularly as the codebase is continually being updated with new features and improvements.

Shiny Application

Predict the Next Word(s)! is a Shiny app that uses a text prediction algorithm to predict the next word(s) based on text entered by a user.

This application suggests the next word in a sentence, based on an n-gram algorithm. An n-gram is a sequence of n words derived from an input sequence of text.

The text used to build the predictive text model came from a large corpus of blogs, news, and Twitter data. N-grams were extracted from the corpus and then used to build the predictive text model.

Various methods were explored to improve speed and accuracy using natural language processing (NLP) and text mining techniques.

The Predictive Text Model

The predictive text model was built from a sample of 800,000 lines extracted from the large corpus of blogs, news, and Twitter data.

The sample data was then tokenized and cleaned using the tm package and a number of regular expressions using the gsub function. As part of the cleaning process, the data was converted to lowercase, removed all non-ascii characters, URLs, email addresses, Twitter handles, hash tags, ordinal numbers, profane words, punctuation, and whitespace. The data was then split into tokens (n-grams).

As text is entered by the user, the algorithm iterates from the longest n-gram (up to a 4-gram) to the shortest (2-gram) to detect a match. The predicted next word is considered using the longest, most frequent matching n-gram. The algorithm makes use of a simple back-off strategy to ensure an output is available.

Application User Interface

The predicted next word will be shown when the app detects that you have finished typing one or more words. When entering text, please allow a few seconds for the output to appear. Use the slider tool to select up to three next word predictions. The top prediction will be shown first, followed by the second and third likely next words.