Word Prediction Application

Roman Vodonenko
8/19/2015

Example

Afetr inputting united states the appication predicts america as the next word

alt text

https://vodonenko.shinyapps.io/word_prediction_app

How to use it

Just type in the phrase and click Pedict the Word alt text https://vodonenko.shinyapps.io/word_prediction_app

How it works

  • It starts from the highest possible N, which is 5 for this app, and N-1 last words from the phrase
  • Thus, it start from the last 4 words from the input phrase and 5-grams
  • If all 4 words found in 5 grams, a 5-gram with the highest frequency is taken and the remaining 5th words, which is not in the input phrase, is returned as prediction
  • If none of 5-grams mathced, the same algorythm is repeated for 4-grams and last 3 words in the phrase and so on down to 2-grams and 1 last word
  • If nothing is found even in 2-grams the app returns the most frequent word, which is “the”

How it works

phrase <- "great wall of"

for(j in 1:5){
  phrase <- paste(phrase, suggest.word(phrase))
  print(phrase)
}
[1] "great wall of china"
[1] "great wall of china s"
[1] "great wall of china s one"
[1] "great wall of china s one child"
[1] "great wall of china s one child policy"