Next Word Predictor

author: Juan González date: September 2026, 26

A Shiny application that predicts the next word in an English phrase.

The goal

  • The user enters a phrase of several words.
    • The application returns one predicted next word.
    • Example: “I want to go” produces “to”.
    • The interface works in a web browser.

The prediction algorithm

  • The training text is converted to lowercase and divided into words.
    • The model counts sequences of one, two and three words.
    • It first looks for words that followed the last two input words.
    • If there is no match, it uses the last word and then overall frequency.

How to use the app

  1. Type an English phrase in the text box.
    1. Click “Predict next word”.
    2. Read the suggested word below the button.

The app displays which training corpus it is using.

Limitations and improvements

  • The result is based on word frequency, so it is not always grammatically correct.
    • Rare phrases may require a shorter context.
    • Training on more text can improve the available predictions.
    • A separate test set could measure prediction accuracy.