This project uses a recurrent neural network (RNN) with Long Short-Term Memory (LSTM) layers to generate text based on Shakespeare's works. The model is trained on a subset of Shakespeare's text and can generate new text sequences based on the learned patterns.
- Python 3.x
- TensorFlow 2.x
- NumPy
You can install the required packages using pip:
pip install tensorflow numpy
Training the Model To train the model, run the main.py script. This script will download the text data, preprocess it, and train the LSTM model.
Run train_model.py to Train the Model
python train_model.py
This script performs the following tasks:
Downloads and reads the Shakespeare text file. Preprocesses the text data into training examples. Builds and trains the LSTM model. Saves the trained model to textgenerator.model/textgenerator.h5.
Generating Text
Once the model is trained, you can use the run.py script to generate text based on the trained model.
Run main.py to Generate Text
python main.py
This script uses the trained model to generate text. You can specify different temperatures to control the randomness of the output. The higher the temperature, the more random the output.
Example Output
The script prints generated text with different temperature settings: