This project is an LSTM-based text generator trained on Shakespeare's works. It uses TensorFlow and Keras to build and train a recurrent neural network that generates text character-by-character, with adjustable randomness via a temperature parameter.
- Loads and preprocesses Shakespeare text from TensorFlow's dataset.
- Builds a character-level LSTM model using Keras.
- Trains the model to predict the next character in a sequence.
- Generates text with adjustable creativity using temperature sampling.
- Saves and loads trained models for reuse.
The training section in Main.py uses the following hyperparameters:
SEQ_LENGTH: Length of each input sequence (default: 40)STEP_SIZE: Step size for moving the window over the text (default: 3)- LSTM units: 128
- Batch size: 256
- Epochs: 10
- Learning rate: 0.01 (RMSprop optimizer)
Feel free to experiment with these hyperparameters to improve model performance or adapt the training process to your needs. Adjusting sequence length, batch size, number of epochs, or the learning rate can have a significant impact on the quality and
-
Install dependencies:
pip install tensorflow numpy
-
Train the model:
- Uncomment the training section in
Main.py. - Run the script to train and save the model as
textgenerator.keras.
- Uncomment the training section in
-
Generate text:
- Comment out the training section and ensure the model loading line is active.
- Run
Main.pyto generate text samples at different temperatures.
Main.py: Main script for training and text generation.textgenerator.keras: Saved Keras model file (created after training).
- Change
SEQ_LENGTHandSTEP_SIZEinMain.pyto adjust input sequence length and training step size. - Modify the number of LSTM units or training epochs for different model capacities.
This project is for educational purposes and uses publicly available

