July 2026

The Problem & The Data

  • Typing on small screens is slow and error-prone; predicting the next word saves keystrokes and time.
  • The model learned from a huge sample of real English text: blogs, news articles, and Twitter — over 100 million words in total.
  • Exploratory analysis showed language is highly repetitive: a few thousand words and phrases cover the vast majority of what people type.
  • That insight lets us build a model small enough to run instantly in a free web app, yet accurate on everyday language.

Johns Hopkins Data Science Capstone (with SwiftKey)

How the Algorithm Works

  1. Offline, we pre-compute frequency tables of 2-, 3- and 4-word phrases (n-grams) from a cleaned 8% sample of the corpus, pruned to the top candidates per phrase.
  2. Online, the app uses Stupid Backoff: it looks up the last 3 words you typed in the 4-gram table; if unseen, it backs off to the last 2 words, then 1, then to the most common English words.
  3. This guarantees a sensible prediction for any input, in a few milliseconds, from a model file of only a few megabytes.
  4. A profanity filter ensures the app never suggests offensive words.

The App

Try it: https://bhargavkumar.shinyapps.io/next_word_app/

  • Type any English phrase in the text box.
  • Press Predict — the most likely next word appears instantly, along with two alternatives.
  • Works on desktop and mobile, no installation required.

(How to use: enter a phrase such as “thanks for the”, click Predict, and read the suggested word in blue. Alternatives appear below it.)

Why It Wins

  • Fast: predictions in milliseconds — all heavy computation was done offline, so the app itself is a simple table lookup.
  • Robust: the backoff design means it never fails to answer, even on slang, typos, or phrases it has never seen before.
  • Scalable: the same pipeline can retrain on any language or domain-specific text (medical, legal, customer support).

Links