Next Word Predictor

Harshal chavhan
2026-10-17

Type a few words. Get the next one, instantly.

A lightweight, fast text-prediction engine built in R and served as a Shiny app.

  • Trained on millions of lines of real blog, news and Twitter text
  • Always returns an answer, even for unseen phrases
  • Small enough to run on a free hosting tier

The Problem & Opportunity

Typing is slow on phones, in chat tools and in support consoles.

  • Predictive text saves keystrokes and reduces errors
  • Most commercial keyboards are black boxes; we built a transparent, tunable one
  • Our model is a few MB, loads in seconds and answers in milliseconds, with no GPU or API calls

Target uses: mobile keyboards, customer-support reply suggestions, accessibility tools.

The Algorithm

N-gram model with Stupid Backoff

  1. Clean a 30% sample of the SwiftKey corpus: lowercase, strip URLs, numbers and symbols, split into sentences
  2. Count 2-, 3- and 4-grams; prune those seen only once
  3. Store the top 5 next words for every context with score = count(context+word) / count(context)
  4. Predict: look up the last 3 words; if nothing matches, back off to the last 2, then 1, multiplying the score by 0.4 per level
  5. Fallback: if no n-gram matches at all, return the most frequent English words, so every input gets an answer

Pruning and top-K storage keep the model small and lookups fast (keyed data.table).

The App

How to use it

  1. Open the app on shinyapps.io
  2. Type a phrase of two or more words, e.g. “thanks for the”
  3. Press Predict (or Enter)
  4. Read the top word in large type and a table of alternatives with confidence scores

Under the hood: the text box input is cleaned and tokenised, the model is queried through the backoff cascade, and results come back in well under a second.

Links: App: your shinyapps.io URL | Code: your GitHub URL

Results & Next Steps

  • Returns a prediction for every input, including rare and unseen word combinations
  • Responds instantly; model file is only a few MB
  • Accuracy figures: add your top-1 / top-3 results from a held-out test here

Roadmap

  • Kneser-Ney smoothing for better rare-word handling
  • Personalisation: learn from each user's own typing
  • Autocomplete of partially typed words
  • Evaluate with top-1 / top-3 accuracy and perplexity on a held-out set

Thank you!