2026-07-11

Predicting What You’ll Type Next

Predicting what you’ll type next — built on real-world text from blogs, news, and Twitter.

  • Typing on mobile is slow. Every keystroke saved matters.
  • This app suggests the next word as you type, based on patterns learned from millions of real sentences.

The Approach

An n-gram language model trained on a sample of the SwiftKey corpus (blogs, news, and Twitter — tens of millions of words of real English).

  • Text is broken into overlapping sequences of 1, 2, and 3 words (unigrams, bigrams, trigrams)
  • Each sequence is scored by how often it actually occurs in real writing
  • Rare, one-off sequences are pruned out, keeping the model small and fast
  • This is the same core idea behind predictive keyboards like the one this project is named after

The Algorithm: Stupid Backoff

A simple, fast, and surprisingly effective strategy:

  1. Look at the last 2 words typed → check the trigram table for the most likely next word
  2. No match? Use just the last word → check the bigram table
  3. Still nothing? Fall back to the single most common word in English

Each step “backs off” to a shorter context only when needed — hence stupid backoff: no fancy statistics, just fast, practical lookups that scale well and run in milliseconds.

The App

A live Shiny app, deployed on shinyapps.io:

  1. Type any partial phrase into the text box
  2. Click Predict next word
  3. The app returns its best guess for what comes next, instantly

Try it yourself: https://yourusername.shinyapps.io/next-word-predictor/

Under the hood: the entire trained model is a few small tables, so the app loads in a couple of seconds — no waiting around, no lag between typing and getting a suggestion.

Why It’s Worth Backing

  • Fast — predictions return in milliseconds, no heavyweight ML inference required
  • Lightweight — small enough to run comfortably on a free hosting tier
  • Practical — trained on real, messy, everyday English, not a sanitized textbook corpus
  • Extensible — the same pipeline scales to more data, deeper n-grams, or smarter smoothing without changing the app’s architecture

This is a solid, working foundation for a predictive-text product — simple enough to ship today, with a clear path to get smarter tomorrow.