Title: Predictive Text with N-gram Language Modeling Author: Ashish Sunar Date: August 2026

The Product

Predict the next word from a phrase

This project builds a lightweight predictive-text system using the English HC Corpora from the SwiftKey Capstone.

Goal

  • Accept a multi-word phrase from a user
  • Predict one likely next word
  • Provide a fast interactive Shiny application

Training data

  • News: 1,010,206 lines
  • Blogs: 899,288 lines
  • Twitter: 2,360,148 lines

The text was cleaned and normalized before word-frequency and n-gram analysis.

===

The Prediction Algorithm

N-gram model with backoff

The model uses neighboring words to estimate the next word.

Prediction flow

  1. Clean and tokenize the user’s phrase
  2. Search for a matching trigram
  3. If unavailable, back off to a bigram
  4. Return the highest-ranked candidate

Model

  • Bigram and trigram frequency tables
  • Trigram → bigram backoff
  • Designed for fast interactive prediction

This approach balances useful context, memory usage, and prediction speed.

===

Shiny Data Product

Simple interface, immediate feedback

The Shiny app provides:

  • A text box for entering a phrase
  • A Predict Next Word button
  • A single predicted word as output

Example tests

Input phrase Prediction
one of the
a lot of
going to
this is a
according to the

Live app: https://asheeshsunar.shinyapps.io/PredictiveText/

The application was successfully deployed on shinyapps.io and tested in a web browser.

===

Evaluation & Performance

Accuracy and speed

Independent testing on News lines produced:

  • Top-1 accuracy: 11.46%
  • Top-3 accuracy: 20.62%
  • Top-5 accuracy: 28.87%

The model was also tested for interactive runtime and produced fast predictions.

Interpretation

The top-1 result shows that next-word prediction is challenging from limited context. The higher top-3 and top-5 results show that useful candidates are often present among the highest-ranked predictions.

===

Conclusion

A practical predictive-text product

Strengths

  • Simple user interface
  • Fast response
  • Trigram context with bigram backoff
  • Browser-accessible Shiny application

Future improvements

  • Better handling of contractions such as it's and don't
  • Improved smoothing and ranking
  • More representative training data
  • More advanced language-model techniques

Takeaway

The project converts large English text corpora into a working predictive-text application while balancing accuracy, memory usage, and response speed.