Next Word Predictor

Sahiti
October 2026

A fast, lightweight app that suggests the next word as you type, the way a phone keyboard does.

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

The problem

  • Typing on small screens is slow; good suggestions save keystrokes.
  • Suggestions must appear instantly and run on limited memory, so a large model is not an option.
  • Goal: predict the next word from the last few words typed, using 4 million lines of English text from blogs, news, and Twitter (SwiftKey corpus).

The algorithm

  1. Clean a 10% sample of the text: lowercase, remove numbers, URLs and symbols, split into sentences.
  2. Count every 1-, 2-, 3- and 4-word sequence.
  3. Prune: drop sequences seen only once and keep the top 5 next words per context. This removes the long tail of typos and one-offs.
  4. Predict with Stupid Backoff: look up the last 3 words; if that phrase was never seen, back off to the last 2, then 1, then the most common words. Each step back multiplies the score by 0.4.

Every input gets a prediction, even phrases that never appear in the training text.

Performance

Tested on 3,000 phrases from text the model never saw:

Measure Result
Correct word ranked #1 16%
Correct word in top 3 26%
Time per prediction 5 ms
Model size in memory 46 MB

Fast and small enough to feel instant on a free shinyapps.io server.

Using the app

  1. Open the app: https://saisahitib.shinyapps.io/next-word-predictor/
  2. Type a phrase in the text box, for example “Thanks for the”.
  3. The predicted next word appears in large text. Press Predict, or just pause typing.
  4. Click one of the three suggestions to add it to your sentence and keep going.

Next steps: a larger training sample, profanity filtering, and learning from each user's own writing.