October 2026

Project Overview

SwiftKey Next Word Prediction Using N-Gram Language Models

Objective: Predict the next word based on the phrase entered by the user.

  • Developed using R and Shiny.
  • Uses text data from blogs, news, and Twitter.
  • Applies statistical language modelling.
  • Provides an interactive next-word prediction interface.

Project Author: Suvrat Verma

Dataset and Exploratory Analysis

Data Sources

The project uses three English-language datasets:

  • en_US.blogs.txt
  • en_US.news.txt
  • en_US.twitter.txt

Data Preparation

  • Loaded up to 2,000 lines from each dataset.
  • Converted text to lowercase.
  • Removed punctuation and normalized whitespace.
  • Split text into words to prepare n-grams.

Total input: Up to 6,000 lines across the three datasets.

Algorithm and Methodology

N-Gram Language Model

The model learns word sequences and their frequencies from the training text.

Model Context Example
Bigram 1 previous word weather → today
Trigram 2 previous words how are → you
Fourgram 3 previous words the weather today → is

Prediction Workflow

  1. Receive a phrase from the user.
  2. Clean and tokenize the input.
  3. Search the fourgram model first.
  4. If no match exists, try trigram and then bigram.
  5. Return the most frequent suitable next word.

Shiny Application Demo

Interactive Next Word Prediction

The user enters a phrase and clicks Predict Next Word.

Live Application:

Open SwiftKey Next Word Prediction App

Technologies Used

  • R programming language
  • Shiny for the interactive web interface
  • N-gram frequency models for prediction
  • rsconnect for deployment to shinyapps.io

Demo Example

Input: The weather today

Output: A predicted next word based on the learned n-gram frequencies.

Actual predictions depend on the available training data.

Conclusion and Future Scope

Conclusion

  • Built an interactive next-word prediction application.
  • Used real-world English text from three sources.
  • Implemented a backoff strategy using fourgram, trigram, and bigram models.
  • Deployed the application to shinyapps.io.

Future Improvements

  • Train on larger and more diverse datasets.
  • Improve text cleaning and prediction quality.
  • Optimize model loading and memory usage.
  • Explore advanced language models and context-aware predictions.

Thank You

Questions and Discussion