2026-08-15

Executive Summary

  • Objective: Develop a smart, fast predictive text application.
  • Problem: Mobile/web text input requires quick, accurate word recommendations.
  • Solution: A data-driven Shiny application leveraging N-gram language modeling with Katz/Stupid Backoff.
  • Key Highlight: High-performance prediction pipeline running sub-second queries.

Exploratory Data Analysis & Corpus

  • Data Sources: Cleaned corpus derived from Twitter, News, and Blog datasets.
  • Preprocessing Steps:
    • Tokenization, lowercasing, and removal of special characters/numbers.
    • Frequency distribution analysis across Unigrams, Bigrams, Trigrams, and 4-grams.
  • Optimization: Filtered low-frequency singletons (\(count > 1\)) to reduce memory footprint by ~75%.

Prediction Algorithm Logic

  • Model: Katz / Stupid Backoff N-gram Model.
  • Cascade Sequence:
    1. Check 4-gram for matches based on last 3 words.
    2. Back off to 3-gram for last 2 words if matches < 5.
    3. Back off to 2-gram / Unigram fallback to guarantee 5 candidates.
  • Efficiency: Uses indexed data.table binary search for \(O(\log N)\) instant lookups.

Shiny Application Overview

  • User Interface (bslib framework):
    • Clean input panel for text entry.
    • Interactive top candidate badge and complete Top-5 recommendation table.
  • User Instructions:
    1. Type a phrase in the input text area.
    2. Click Predict Next Word.
    3. View ranked predictions with confidence levels.

Conclusion & Resources

  • Performance: Low latency, low memory footprint, and cloud-hosted on Posit infrastructure.
  • Future Improvements: Inclusion of neural network language models (LSTMs) and domain-specific dictionaries.
  • Links: