2026-07-23

Problem Statement

With the proliferation of mobile devices, typing quickly and accurately on small keyboards is a significant challenge.

The goal of this project is to create a predictive text model that suggests the next word as the user types.

  • Dataset: HC Corpora containing English texts from Blogs, News, and Twitter.
  • Objective: Build an efficient, fast, and accurate Natural Language Processing (NLP) model.
  • Platform: R and Shiny.

Algorithm

The prediction engine is based on an N-gram Language Model with a Katz-style Backoff strategy.

  1. Preprocessing: Text is converted to lowercase; punctuation, URLs, numbers, and extra spaces are removed.
  2. N-gram Generation: The data is tokenized into Unigrams, Bigrams, Trigrams, and Fourgrams.
  3. Prediction Logic:
    • Try to find the last 3 words in the Fourgram model.
    • If no match, backoff to the Trigram model (using the last 2 words).
    • If no match, backoff to the Bigram model (using the last word).
    • If still no match, return the most frequent Unigram.

Shiny App Demo

The application provides a clean, modern user interface.

  • Input: A text box where the user can type a sentence.
  • Action: A “Predict Next Word” button.
  • Output:
    • The predicted word highlighted in red.
    • Information on which n-gram model was utilized.
    • Response time (ensuring predictions are < 1 second).

Screenshot placeholder: [Insert Shiny App Image Here]

Results and Future Improvements

Results: - The model responds incredibly fast, almost always under 0.1 seconds. - Memory usage was optimized by filtering out low-frequency n-grams and using data.table.

Future Improvements: - Implement Good-Turing smoothing or Kneser-Ney smoothing for better handling of unseen n-grams. - Introduce a spell-checker before processing the input. - Expand the dictionary by training on a larger subset of the corpus.

Thank You