2026-07-21

Predicting the Next Word

What is this project?

  • The application predicts the next word in a sentence;
  • It was built using English text from blogs, news articles and Twitter;
  • Demonstrates a simple predictive text application;
  • The app was developped in R using Shiny.

Why is it useful?

  • It demonstrates how predictive text works using language models;
  • Suggests the most likely next word;

How the Model Was Built?

Training the model

The model was trained using text from three different sources:

  • Blogs, news, and Twitter.

The text was:

  • Converted to lower case;
  • Split into individual words (tokenised);
  • Used to create 1-gram to 5-gram models.

Each model stores the most likely word to appear next.

How Predictions Are Made

Back-off strategy

When a user enters some text, the model first looks for the longest matching sequence of words.

5-gram → 4-gram → 3-gram → 2-gram

If no match is found, it gradually uses a shorter sequence until a prediction is available.

The app then displays:

  • The most likely next word;
  • Up to three additional suggestions.

Demonstration

Using the application

  1. Enter a sentence into the text box;
  2. Click Predict Next Word;
  3. View the suggested next word and other possible options.

Example

Input: I would like to

Output:

Summary

Project highlights

  • Uses real English language data;
  • Predicts the next word using n-gram models;
  • Applies a back-off strategy to improve prediction coverage;
  • Provides a simple and easy-to-use Shiny interface.

Try the application: