Skip to content

ShakespeareGPT generates text in the style of Shakespeare using an LSTM-based neural network trained on his works. Features include text generation from a 6-word input, beam search for quality, temperature sampling, and an interactive GUI. The model uses early stopping and is saved for future use.

Notifications You must be signed in to change notification settings

Mahmoud-K-Ismail/ShakespeareGPT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShakespeareGPT

ShakespeareGPT is a text generation model designed to emulate the writing style of William Shakespeare. This project leverages deep learning techniques, specifically using Long Short-Term Memory (LSTM) networks, to generate Shakespearean-style text. The model is trained on the complete works of William Shakespeare and can produce coherent paragraphs that mimic the bard's unique style and vocabulary.

Features

  • Deep Learning Model: Utilizes an LSTM network to capture the sequential nature of Shakespeare's writing.
  • Text Generation: Capable of generating text that mimics the style and tone of Shakespeare.
  • Customizable Generation: Allows users to control the length and structure of the generated text, including sentence count and temperature for sampling.
  • Beam Search: Implements beam search algorithm for generating more coherent and contextually accurate text.
  • Interactive GUI: Includes a user-friendly graphical interface for inputting prompts and displaying generated text.

Models:

  • model_1: will be referred to as the "Index-Based Model".
  • model_emb_m2m: will be referred to as the "One-Hot-Encoding-Based Model".

Getting Started

Prerequisites

  • Python 3.8 or higher
  • TensorFlow
  • Keras
  • NLTK
  • NumPy
  • Matplotlib

Installation (Still ongoing)

  1. Clone the repository:
    git clone https://github.com/yourusername/ShakespeareGPT.git
    cd ShakespeareGPT

2.Install the required packages:

pip install -r requirements.txt
  1. Download the dataset: The model is trained on the complete works of William Shakespeare from Project Gutenberg. This script will automatically download and preprocess the data.

Training the Model

  1. Initialize the dataset:
   python preprocess.py
  1. Train the model:
   python train.py
  1. Save the trained model: The model will be saved as model.h5 in the project directory.

Generating Text

  1. Run the interactive script:

       python generate.py
  2. Enter a 6-word sentence as a prompt and the model will generate a Shakespearean paragraph based on it.

Usage

You can use the interactive script to generate text or integrate the model into other applications. The GUI allows for easy input of prompts and viewing of generated text.

Example

   input_text = "From fairest creatures we desire increase,"
   output = generate_sample(model, input_text.lower(), num_sentences=4, temperature=0.7)
   print(output)

Contributing

We welcome contributions! Please read our Contributing Guidelines for more information on how to contribute to this project.

Acknowledgments

Project Gutenberg for providing the dataset. Keras and TensorFlow for the deep learning framework. NLTK for natural language processing tools.

About

ShakespeareGPT generates text in the style of Shakespeare using an LSTM-based neural network trained on his works. Features include text generation from a 6-word input, beam search for quality, temperature sampling, and an interactive GUI. The model uses early stopping and is saved for future use.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages