Next Word Prediction using N-grams Language Model and Shiny App

Radu-Ionel TOMA
04-03-2023

The Problem of Next Word Prediction

  • The task of predicting the next word in a sentence or phrase is a common problem in natural language processing.
  • It is important to accurately predict the next word in order to improve the quality of natural language processing applications like language translation, text summarization, and text generation.
  • However, predicting the next word in a sentence is a difficult task because it depends on the context of the sentence and the vocabulary of the language.

Our Solution: N-grams Language Model

  • The data set used to train the model is a collection of text data, which can be downloaded from HC Corpora database.
  • The data is preprocessed by tokenizing the words and converting them to numerical values.
  • The data is then split into n-grams (in this case, trigrams)
  • The algorithm is based on the n-gram model which is a probability based model.
  • The n-gram model uses the frequency of words in a text to predict the next word in a sentence.

Interactive Web App: Next Word Prediction

The “Interactive Web App: Next Word Prediction” is hosted HERE.

App's functionality:

  • The Shiny app takes as input a phrase (multiple words) in a text box input and outputs a prediction of the next word.
  • The app is built with R and Shiny, an open-source framework for creating web applications in R.
  • The app allows users to easily interact with the prediction algorithm and get immediate results.

Benefits of the app:

  • The app makes it easy for users to understand and use the algorithm without the need for technical expertise.
  • The app allows for real-time interaction with the algorithm, which can be useful for understanding the algorithm's behavior or for testing different inputs.
  • The app can be easily shared with others, making it easy to collaborate on the algorithm.

Conclusion

  • The problem of next word prediction is a common problem in natural language processing
  • We proposed a solution using an n-grams language model that uses the frequency of words in a text to predict the next word in a sentence.
  • We built a Shiny app that allows users to interact with the algorithm and get immediate results.

Next steps or future work:

  • We plan to further improve the model by incorporating other techniques such as deep learning
  • We plan to test the model on other languages
  • We plan to add more features to the Shiny app to make it more user-friendly and interactive.