SwiftKey Next Word Prediction

Louis Natasha Voudy Nanlessy
2026-06-08

Problem and Goal

Typing on mobile devices is often slow and error-prone. A predictive keyboard can reduce typing effort by suggesting the next word before the user finishes typing.

Goal: build a Shiny app that takes a phrase as input and predicts the next word.

Data and Exploration

The model uses English text from three sources:

  • Blogs
  • News
  • Twitter

The exploratory analysis focuses on word frequency, bigrams, trigrams, and common language patterns. The data is cleaned by lowercasing text, removing URLs, removing non-letter symbols, and trimming spaces.

Prediction Algorithm

The app uses an n-gram backoff model:

  1. Try a 4-gram match using the last 3 words.
  2. If not found, try a 3-gram match using the last 2 words.
  3. If not found, try a 2-gram match using the last word.
  4. If still not found, return the most frequent words.

This approach is simple, fast, and suitable for an interactive Shiny app.

Shiny App

The Shiny app contains:

  • A text input box for the user's phrase
  • A submit button
  • A prediction output showing the top suggested next words

Example input:

I went to the

Example output:

store, gym, beach

Value and Next Steps

The model demonstrates how text data can be transformed into a useful data product. It is lightweight enough for deployment and easy to explain to non-technical users.

Future improvements may include larger training samples, profanity filtering, smoothing, and better handling of punctuation and unknown words.