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.
| 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 |
- 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.
- Python 3.10+
- pip
-
Clone the repository:
git clone https://github.com/Pranamchand/Next-Text-Predictor-Model.git cd Next-Text-Predictor-Model -
Install dependencies:
pip install -r requirements.txt -
Run the application:
streamlit run app.pyOr on Windows, double-click
run_app.bat. -
Open in browser:
Navigate to
http://localhost:8501.
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
- Optimizer: Adam
- Loss Function: Categorical Crossentropy
- Epochs: 10
- Batch Size: 120
- Validation Split: 10%
- Platform: Google Colab (T4 GPU)
| Layer | Technology |
|---|---|
| Frontend | Streamlit , Antygravity |
| Deep Learning | Keras 3, PyTorch |
| Data Processing | NumPy, Pandas |
| Model Format | HDF5 (.h5) |
| Serialization | Pickle |
- Enter a seed phrase like
"the world is"in the text input. - Adjust the number of words to predict using the sidebar slider.
- Click 🚀 Predict Next Words.
- View the predicted completion and probability breakdown.
- Click 📋 Use Completion as New Prompt to continue generating.
Built with ❤️ using Keras, PyTorch & Streamlit Frontend with Antygravity