Skip to content

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.

Notifications You must be signed in to change notification settings

bhushankhopkarr/poetictexts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Text Generation with Shakespeare's Works

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.

Prerequisites

  • 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:

Temperature 0.2
Screenshot 2024-06-19 130229

Temperature 0.4
Screenshot 2024-06-19 130236

Temperature 0.6
Screenshot 2024-06-19 130242

Temperature 0.8
Screenshot 2024-06-19 130256

Temperature 1.0
image

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages