Skip to content

Repository files navigation

⚡ Next Text Predictor Model

A deep learning-powered next word prediction application built with an LSTM (Long Short-Term Memory) neural network, served through a sleek Streamlit web interface. The model is trained on a curated dataset of 3,000+ literary and philosophical quotes, enabling it to generate contextually relevant word completions in real time.

This Model is only the cheap version of the real thing due to lack of resources , a much better version can be made using Transformers and larger datasets and proper training on T4 gpu for more than 80 epochs.


🎯 Project Overview

Feature Details
Architecture Embedding → LSTM → Dense (Softmax)
Vocabulary ~8,978 unique tokens
Embedding Dimension 50
LSTM Hidden Units 120
Max Sequence Length 745 tokens
Trainable Parameters 1,792,080 (~6.84 MB)
Training Dataset 3,038 literary & philosophical quotes
Backend Keras 3 with PyTorch backend

🖥️ Features

  • Real-Time Prediction — Type any seed phrase and instantly see the model's predicted next words.
  • Multi-Word Generation — Generate up to 30 sequential words from a single prompt.
  • Top-K Probability Visualization — Inspect the confidence distribution across the top candidate words with interactive progress bars.
  • Temperature Sampling — Toggle between deterministic (argmax) and creative (temperature-scaled) generation modes.
  • One-Click Word Append — Click any candidate word to append it to your prompt and continue generating.
  • Preset Prompts — Quick-start buttons with curated seed phrases from the training corpus.
  • Token Inspector — View the cleaned text, token IDs, and sequence length for any input.
  • Model Comparison — Optionally load a SimpleRNN baseline model for side-by-side comparison.

🚀 Getting Started

Prerequisites

  • Python 3.10+
  • pip

Installation

  1. Clone the repository:

    git clone https://github.com/Pranamchand/Next-Text-Predictor-Model.git
    cd Next-Text-Predictor-Model
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Run the application:

    streamlit run app.py
    

    Or on Windows, double-click run_app.bat.

  4. Open in browser:

    Navigate to http://localhost:8501.


🧠 Model Architecture

The model follows a standard sequence-to-one architecture for next word prediction:

Input Text
    │
    ▼
┌─────────────────────┐
│  Text Preprocessing  │  Lowercasing, punctuation removal
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│     Tokenization     │  Keras Tokenizer (vocab_size = 10,000)
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│   Sequence Padding   │  Pre-padding to max_length = 745
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│  Embedding Layer     │  10,000 → 50 dimensions
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│    LSTM Layer        │  120 hidden units
└──────────┬──────────┘
           │
           ▼
┌─────────────────────┐
│   Dense + Softmax    │  10,000 output classes
└──────────┬──────────┘
           │
           ▼
      Predicted Word

📊 Training Details

  • Optimizer: Adam
  • Loss Function: Categorical Crossentropy
  • Epochs: 10
  • Batch Size: 120
  • Validation Split: 10%
  • Platform: Google Colab (T4 GPU)

🛠️ Tech Stack

Layer Technology
Frontend Streamlit , Antygravity
Deep Learning Keras 3, PyTorch
Data Processing NumPy, Pandas
Model Format HDF5 (.h5)
Serialization Pickle

📝 Usage Example

  1. Enter a seed phrase like "the world is" in the text input.
  2. Adjust the number of words to predict using the sidebar slider.
  3. Click 🚀 Predict Next Words.
  4. View the predicted completion and probability breakdown.
  5. Click 📋 Use Completion as New Prompt to continue generating.

Built with ❤️ using Keras, PyTorch & Streamlit Frontend with Antygravity

About

LSTM-based next-word prediction model trained on 3,000+ literary and philosophical quotes. Built an Embedding → LSTM → Dense architecture with a SimpleRNN baseline for comparison. built with limited compute, designed to scale toward Transformers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages