╔════════════════════════════════════════════════════════════╗
║ Project : AI Next Word Prediction ║
║ Model : LSTM RNN Language Model ║
║ Dataset : Shakespeare Hamlet Text ║
║ Framework : TensorFlow / Keras + Streamlit ║
║ Author : ASHITOSH ║
╚════════════════════════════════════════════════════════════╝
AI Next Word Prediction is a deep learning NLP project that predicts the next word for a given text sequence. The model is trained on Shakespeare's Hamlet text using an LSTM-based Recurrent Neural Network.
The project includes:
- 🧠 A trained LSTM next-word prediction model
- 🔤 A saved tokenizer for text-to-sequence conversion
- 📚 Hamlet text dataset
- 📓 Training and experimentation notebook
- 🚀 A deployable Streamlit web application
- ✅ Predicts the next likely word from user input
- ✅ Uses n-gram sequence generation for language modeling
- ✅ Pads sequences before model inference
- ✅ Uses a trained Keras
.h5model - ✅ Provides a simple Streamlit UI
- ✅ Ready for local running and Streamlit Cloud deployment
LSTM_RNN_imple/
├── .streamlit/
│ └── config.toml
├── app.py
├── experiments.ipynb
├── hamlet.txt
├── next_word_prediction_model.h5
├── README.md
├── requirements.txt
├── runtime.txt
└── tokenizer.pickle
The model pipeline follows these steps:
| Step | Description |
|---|---|
1 |
Collect Hamlet text data using NLTK / Gutenberg |
2 |
Tokenize text with tensorflow.keras.preprocessing.text.Tokenizer |
3 |
Create n-gram input sequences from each line of text |
4 |
Pad all sequences to a fixed length |
5 |
Split data into predictors and labels |
6 |
Convert labels into categorical vectors |
7 |
Train an LSTM RNN model |
8 |
Save the trained model and tokenizer for inference |
┌─────────────────────────────────────────┐
│ Embedding(total_words, 100) │ ← Word vectors
├─────────────────────────────────────────┤
│ LSTM(150, return_sequences=True) │ ← Sequence layer 1
├─────────────────────────────────────────┤
│ Dropout(0.2) │ ← Regularization
├─────────────────────────────────────────┤
│ LSTM(100) │ ← Sequence layer 2
├─────────────────────────────────────────┤
│ Dense(total_words, activation= │
│ "softmax") │ ← Output probabilities
└─────────────────────────────────────────┘
cd "LSTM_RNN_imple"python -m venv venvWindows with TensorFlow support:
py -3.11 -m venv venvWindows:
venv\Scripts\activatemacOS/Linux:
source venv/bin/activatepip install -r requirements.txtstreamlit run app.pyThen open:
http://localhost:8501
When the user enters text:
| Step | Action |
|---|---|
1 |
Input text is converted into token IDs |
2 |
Token list is trimmed if longer than model input length |
3 |
Sequence is padded |
4 |
LSTM model predicts probabilities for all known words |
5 |
Word with highest probability is returned as the next word |
Example:
┌─────────────────────────────────┐
│ Input : to be or not to │
│ Output : be │
└─────────────────────────────────┘