For this final submission, we had to:
- Create a data product to show off the prediction algorithm. We created a Shiny app that accepts an n-gram and predicts the next word.
- Create a slide deck promoting the application using RStudio Presenter.
2024-04-14
For this final submission, we had to:
The corpus used for this predictive text algorithm was constructed from the three original files that include text from blogs, tweets, and news, taking a 10% sample from each file. This was accomplished through a processing of the data which included:
Once the data was cleaned, the corpus was generated. Then, the data was tokenized to generate three RData files that included n-gram frequencies for unigrams, bigrams, and trigrams.These files were what the model used!
The algorithm is designed to take an input, and then iterate the text from a trigram to a unigram, trying to find a match. Once it has found the longest, matching n-gram, it uses a Katz back-off, as shown below, designed to estimate the conditional probability of each word given its history in the n-gram (its maximum likelihood state of that n-gram according to our frequency files). The model backs off through progressively shorter models (n-1)-gram, trying to find the one with the most reliable information.
Back off is very inexpensive to calculate, which ensures out app runs fast without losing too much precision in its predictive power!
Find the app here: [https://miresol.shinyapps.io/Predictive3/]
This app lets you use the English predictive text algorithm previously described. You can write any sentence you want into the input box and watch how the model predicts the next word! You are able to choose between 1, 2, or 3 possible next words using the slider; these words will be ranked according to their probability so you can get an idea of the top most likely words that fit your sentence.
This app was designed to be slick and easy to use, so that even inexperienced users could try it out. However, it was necessary to remove the modelling of n-grams that were longer than 3 (like quadgrams) to ensure it would run fast enough; further implementations should try to improve these time constraints to improve the model and the experience of using the app.