I used the Katz Backk-off approach with good turing as smoothing technique. First, I created a function to perform Good Turing, it redistributes the counts of the n-grams. After calling the function we have a table with n-gram count, the new estimated probability, and a variable d or amount of discounting. I did this for bi-gram, three-grams, four-grams and five-grams.
In the next step a function was created to predict the next word given a phrase, this function takes the phrase and the n-grams previously created and assigns a probability to every word present in the corpus, this is the probability of being the next word given its history, using the Katz back-off approach. In the shiny app application, the model will check for the history of the phrase in the three-gram, when it is not present, it will then check the bi-gram.