Next Word Prediction: SwiftKey Capstone

2026-08-07

An n-gram based, text prediction engine, deployed as an interactive Shiny application

The Problem

  • Mobile keyboards need to predict the next word instantly, from limited context
  • The goal of this app is to uggest the most likely next word in real time given a phrase
  • Constraints that matter in production: speed, memory footprint, and accuracy- all trade off against each other

Our Approach

  • The model is trained on a sample of the SwiftKey corpus (blogs, news, Twitter)
  • 2-gram, 3-gram, and 4-gram frequency tables are built from cleaned, tokenized text
  • Prediction uses a backoff strategy: check the richest context first (last 3 words), fall back to shorter context if and when data is sparse
  • Implemented in R using quanteda (tokenization) and data.table (fast indexed lookup) for production-grade speed at scale

The App

  • It is bilt and deployed as a Shiny web app
  • Has a simple interface: type a phrase and get the top 10 next-word predictions instantly
  • Lookup tables are pre-built and cached, so predictions return in milliseconds
  • Try it at https://anusha123.shinyapps.io/Prediction_app/

Results & Next Steps

  • Model produces contextually sensible predictions for common phrasing
  • Known limitation: rare/idiomatic phrases (e.g. proverbs, song lyrics) need more training data to predict reliably - an expected trade-off of sample size vs. speed/memory
  • Next steps to improve accuracy:
    • Train on a larger sample of the corpus
    • Explore smoothing techniques for better handling of rare contexts
    • A/B test with real users to tune the model in production