2024-03-03

Project Overview

This capstone project creates a text prediction model in which a multi-word phrase is taken as input and a prediction of likely next words is made.

App Instructions

From a client perspective, the application is extremly simple. The user simply needs to type one or more words into the “Input text” field. The model will then calculate the most likely “next” words and display the top 3 predictions.

Prediction Algorithm

  • The prediction model was developed using strings of text from blog, news and twitter entries from the internet.
  • Each line of text was parsed into n-grams of size 2, 3 and 4 tokens
  • The frequency of each n-gram prefix was calculated to determine the probability of the last token in the n-gram
  • User input strings are then parsed and compared to n-gram prefix string in the model looking for a match. If a match is not found for the trailing tri-gram in the user input string, a match is search for using the trailing bi-gram and then uni-gram.
  • Finally, a rudimentary backoff model is used for very low frequency matches to improve the overall model accuracy

Data Statistics

Model Data Lines Words
blogs_en.txt 899,288 37,334,690
news_en.txt 1,010,244 34,372,720
twitter_en.txt 2,360,148 30,374,206
Unique N-Grams Count
Tri-Grams 42,935,040
Bi-Grams 13,585,630
Uni-Grams 830,635