Next Word Prediction

author: VK date: September 2026 autosize: true

Data Science Capstone Project

A simple NLP application that predicts the next word from a phrase.

Based on English blogs, news and Twitter text.

Prediction Algorithm

The application uses an n-gram based prediction approach.

  • The text data is cleaned and converted into words.
  • Common bigrams and trigrams are extracted.
  • The most frequent word sequences are stored in the model.
  • When a user enters a phrase, the last words are used for prediction.
  • Trigram matching is attempted first, followed by lower-order sequences when needed.

The model balances prediction quality with speed and memory usage.

Model Performance

The exploratory analysis used a sample of 30,000 lines from the three English data sources.

Key quantitative results:

  • Total tokens analyzed: 879,665
  • Unique words covering about 50% of the text: 139
  • Unique words covering about 90% of the text: 7,067
  • Top 10 bigrams and trigrams were identified from the sample.
  • The final model stores the most frequent 10,000 unigram words.

For the final application test, 5 sample phrases were entered and the application produced a single-word prediction for all 5 phrases.

Shiny App

The final product is a Shiny web application.

How it works:

  1. Enter a phrase in the text box.
  2. Click “Predict Next Word”.
  3. The application analyzes the entered phrase.
  4. The model searches for matching word sequences.
  5. A single predicted next word is displayed.

The application is deployed on shinyapps.io and can be accessed through a web browser.

Results and Conclusion

The project demonstrates a practical NLP next-word prediction system.

Main outcomes:

  • English text from blogs, news and Twitter was analyzed.
  • Word, bigram and trigram frequencies were explored.
  • An n-gram prediction model was developed.
  • A Shiny interface was created for real-time prediction.
  • The application successfully produced predictions for test phrases.

The project focuses on a simple, fast and usable prediction experience.