Thetazero Pubs
anjankarkiprakash

Predict The Next Word

Anjan Prakash Karki
April 26, 2016DATA_ADSENSE

Next Word Predictor

The purpose of this project is to built a Shiny application to predict the next word based on the last 1, 2 or 3 words entered by the user.

For this purpose, this isan intuitive Application that Predicts the next Word!

Word Predictor can be implemented on mobile devices and offers advantages over standard text typing:

  • Improved typing speed
  • Improved spelling and accuracy

Predict Next Word(How does it work?)

  • Word Predictor is an interactive Shiny R application that can predict the word based on the phrase/sentence/word you enter.

  • Word Predictor uses the n-grams data set determining word frequency.DATA_ADSENSE

Here are the steps of how it works:

  1. The user enters the required phrase, sentence or word.
  2. The application utilizes its trained Decision Tree to figure out which word occurs next.
  3. The application outputs the results

The Internal of the application

The application, at the core, uses N-Gram model for prediction.

  • Backoff algorithm is used for the prediction where it is recursively trying from the higher order of n-gram data frame to lower order of n-grams data frame until a reasonable probability is found.

  • E.g. If the input is more than 3 words, compare the last 3 words of the input to the first 3 words of the quadGram data frame. If an appropriate match is not found, then compare the last 2 words of the input to the first 2 words of the triGram data frame.

Try the Application

https://anjanprakash.shinyapps.io/NextWordPredict/

Code Snippet

number <- floor(runif(1,1,1001))
numberGuessed <- function(guess, number) {
  returnValue <- "Nothing entered yet."
  if (guess > 1000) {returnValue <- 'Above 1000.\nPlease make a selection between 1 and 1000.'}
  else if (guess < 1) {returnValue <- 'Below 1.\nPlease make a selection between 1 and 1000.'}
  else if (guess > number) {returnValue <- 'Higher than the number.'}
  else if (guess < number) {returnValue <- 'Lower than the number.'}
  else if (guess == number) {returnValue <- 'Correct!'}
  returnValue
}
Copyright © 2016 thetazero.com All Rights Reserved. Privacy Policy