2022-07-22

Prediction Model

This function use the unigram, bigram and trigram to predict the next word.
It will return the top 10 most probable result according to the n-grams.

  1. It first check if there is any row in the trigram match the last two words in the sentence. If yes, it returns the top 10 highest proportion result.

  2. If there is no row in the trigram that matches the sentence, it check from the bigram and return the result if it can find any row that matches.

  3. If it still could not find any matches, it will return the top 10 highest frequency word in the unigram.

Performance

start_time <- Sys.time()
pred("My granny has some old bagpipes in her garage I'll dust them off and be on my")
## [1] "way"
time_diff <- Sys.time() -
    start_time

The time used is 0.5124419 secs

User Interface

Other functions

  • Generate sentences
  • N-grams phrase table and plot