Next Word Prediction App

Da Le

A lightweight Shiny product that predicts the next word after a user enters an English phrase.

The goal is practical: fast, simple, and understandable enough for a non-technical user.

Data and Preprocessing

The model is built from the Coursera SwiftKey English corpus:

  • Blogs: longer informal writing
  • News: formal edited writing
  • Twitter: short conversational text

Preprocessing steps:

  • Convert text to lowercase
  • Remove URLs, numbers, and punctuation noise
  • Normalize whitespace
  • Tokenize text into word sequences
  • Build n-gram frequency tables

Prediction Algorithm

The app uses an n-gram back-off model.

Example input:

I am going to

The algorithm checks contexts from longest to shortest:

  1. am going to -> likely next word
  2. going to -> likely next word
  3. to -> likely next word

This gives a good balance between coverage and speed.

Shiny App Experience

The app is intentionally simple:

  • User types a phrase into a text input box
  • User clicks Predict next word
  • The app returns one predicted word

The app does not require statistical knowledge. It behaves like a small predictive keyboard prototype.

Typical examples:

  • I love -> you
  • new york -> city
  • thank you for -> the

Product Value and Next Steps

Why this approach works:

  • Compact enough for shinyapps.io
  • Fast enough for interactive use
  • Easy to explain and maintain
  • Can improve by training on larger samples

Next improvements:

  • Tune n-gram pruning thresholds
  • Add profanity filtering
  • Evaluate accuracy on held-out text
  • Display top three predictions instead of only one

This product demonstrates a working data product pipeline: corpus processing, model compression, prediction logic, and a public Shiny interface.