2024-02-06

Introduction and Motivation

The goal of the capstone project was to build a text prediction algorithm. This project mimics what a normal data scientist might experience in a work setting by requiring participants to learn more about the advanced techniques and topics required to complete the project. To complete the project, further investigation into natural language processing, n gram models, and backoff models were required along with the utilization of previous topics covered in the course such as shiny apps, statistical inference, visualization, and markdown presentations.

Background and Data Sources

SwiftKey is a company that employs a smart keyboard that uses predictive text models on their devices. They have released datasets from three different sources to use:

  • Blogs
  • News
  • Tweets

Exploratory data analysis was performed on the data with the lens of building a prediction algorithm. Then, the data was sampled (for runtime and memory efficiency) to build a corpus of text for use in the prediction algorithm.

Description of the Algorithm

The Algorithm Employs:

  • An n-gram stupid backoff approach in which the input text is compared to partial n-grams and then backed down 5-1 grams in order to find the best prediction for the next word.
  • A stupid backoff score (SBO Score) to rank the likelihood that the predicted word is supposed to come next (based on our sample corpus). Each time the algorithm backs off, the alpha (0.4) is squared by a factor of the number of backoffs (i.e. a tetragram score in our model would be (0.4^2)*frequency in the corpus)
  • Note, with the size limitation for github uploads, the sample size for the predictions is rather small (5% of total rows in the data) which leads the algorithm to commonly return the top unigrams when no matches are found

Use of the App

  • First, select the ‘Number of Predictions’ you’d like the algorithm to make using the slider
  • Second, input a word or phrase in the text box that you’d like to predict the next word for
  • Third, click the submit button to see the predictions and Probability (SBO Score) generated in the table

Link to App