Next Word Predictor

Athithyan Selvarajan
juillet 30, 2026

Predicting your next word, like a smartphone keyboard.

The Problem

  • Smartphone keyboards suggest the next word as you type
  • Goal: build the same kind of predictive text model, trained on real written English (blogs, news articles, and tweets from the SwiftKey corpus)
  • Given a phrase like “I want to go”, the app should suggest a plausible next word (e.g. “home”, “to”, “the”)

The Algorithm

A Stupid Backoff n-gram language model:

  1. Look at the last 2 words typed. If that 3-word sequence (trigram) was seen often enough in training, predict the word that most commonly followed it.
  2. If not found, back off to just the last word (bigram model).
  3. If still not found, fall back to the most common word overall in the training corpus.
  context pred freq
1  i want   to  120
2 want to   go   95

The App

  • Built with Shiny, deployed on shinyapps.io
  • User types a phrase in a text box and clicks “Predict next word”
  • The app shows:
    • the top predicted word, in large text
    • a small table of the top candidate words considered
    • which model level was used (trigram / bigram / fallback), for transparency

Try it live: https://athi-9.shinyapps.io/word_predictor/

Why It Matters

  • Even this lightweight, “stupid” backoff approach captures a lot of everyday English phrasing, because common phrases repeat constantly across blogs, news, and tweets
  • The model stays small and fast (only the top few candidates are kept per context), which is exactly what's needed for a responsive, production-ready typing assistant
  • Next steps for a real product: smarter smoothing (Kneser-Ney), personalization to a specific user's writing style, and support for emoji / multi-word phrases

Thank you!