Word Prediction App: N-gram Model for Text Prediction

Taiki Matsugi
2025-04-25

The Problem and Solution

The Challenge:

  • People need faster ways to enter text on mobile devices
  • Predictive text can significantly reduce typing effort
  • Modern keyboards need smart, efficient prediction algorithms

Our Solution:

  • A fast, memory-efficient next word prediction model
  • Based on N-gram analysis of large text corpora
  • Uses a sophisticated backoff model for accurate predictions
  • Deployed as a user-friendly Shiny application

The N-gram Model Architecture

INPUT → PREPROCESSING → PREDICTION
Quadgram → Trigram → Bigram → Unigram

Key Features:

  • Hierarchical backoff model
  • Fast lookup data structures
  • Confidence scoring
  • Clean text preprocessing

The Shiny Application

Application Features:

  • Real-time next word prediction
  • Simple, intuitive user interface
  • Click-to-add predicted words
  • Displays prediction confidence and model used
  • Optimized for speed and responsiveness

How to use it: 1. Type text in the input box 2. View the top predictions 3. Click on a predicted word to add it 4. See which model made the prediction

Performance and Next Steps

Model Performance:

  • Prediction time: <50ms on average
  • Memory usage: Optimized for mobile/browser environments
  • Accuracy: ~28% Top-1, ~45% Top-3 on test corpus

Future Improvements:

  • User-specific adaptation to personal writing style
  • Domain-specific models (email, social, academic)
  • Integration with mobile keyboard frameworks
  • Hybrid neural-statistical models for improved accuracy

Conclusion: A practical, efficient solution for real-world text prediction needs.