This project is a simple implementation of a next word prediction model using a Long Short-Term Memory (LSTM) network. The model is trained on a custom dataset of FAQs to generate text that mimics the style of the source text.
- Text Preprocessing: Cleans and tokenizes the input text data.
- Sequence Generation: Creates n-gram sequences for model training.
- LSTM Model: A simple Keras-based LSTM model to learn text patterns.
- Text Generation: Predicts and generates a sequence of words based on a starting phrase.
Here's a quick look at the model in action after training:
- Python 3.10
- TensorFlow 2.12
- NumPy 1.23
- Keras (as part of TensorFlow)
Follow these steps to set up the project locally.
-
Clone the repository:
git clone [https://github.com/jsonusuman351/Nextwordpredict.git](https://github.com/jsonusuman351/Nextwordpredict.git) cd Nextwordpredict
-
Create and activate a virtual environment:
# Create the venv using Python 3.10 conda create -p venv python==3.10.0 # Activate it conda activate venv/
-
Install the required packages:
pip install -r requirements.txt
Once the setup is complete, you can run the project.
-
Train the Model: This script will preprocess the data, build the LSTM model, train it, and save the trained model and tokenizer in the
saved_models/
directory.python src/train.py
-
Generate Text: After training, run this script to see the predictions. You can change the starting text inside the
predict.py
file.python src/predict.py
Example Output:
-------------------------------------------------- Seed Text: 'what is the duration' Generated Text: 'what is the duration of the course is 7 months so the total course' --------------------------------------------------
Click to view the folder structure
Nextwordpredict/
│
├── .gitignore
├── README.md
├── requirements.txt
│
├── data/
│ └── faqs.txt
│
├── saved_models/
│ └── .gitkeep
│
└── src/
├── __init__.py
├── data_preprocessing.py
├── model.py
├── train.py
└── predict.py