LSTM_RNN is a deep learning project that employs Long Short-Term Memory (LSTM) networks to generate text in the style of Shakespeare. Trained on the hamlet dataset(text of William Shakespeare), this model captures the nuances of Early Modern English to produce coherent and stylistically consistent text.
- Character-Level Text Generation: Generates text one character at a time, predicting the next character based on the previous sequence.
- Trained on Shakespeare's Works: Utilizes the dataset from [The Tragedie of Hamlet by William Shakespeare 1599] to learn the intricacies of Shakespearean language.
- Streamlit Interface: Provides an interactive web application for real-time text generation.
To run this project, ensure you have the following Python packages installed:
tensorflowstreamlitnumpypickle
Input text is tokenized at the character level, creating sequences of fixed length.
Each sequence of characters is mapped to integer indices representing the characters.
Sequences are padded to ensure consistent input dimensions for the LSTM.
Embedding Layer: Converts character indices into dense vectors.
LSTM Layers: Captures sequential dependencies and long-term context in the text.
Dense Output Layer: Applies a softmax activation to predict the probability distribution over the next character.
Optimizer: Adam
Loss Function: categorical_crossentropy
Sequence Length: Customizable input length (e.g., 40 characters per sequence)
Early Stopping can be applied to prevent overfitting and ensure generalization.
Given a seed text, the model predicts the next character iteratively to generate text.
Uses a sliding window over the seed text to ensure context length matches the trained sequence length.
Can generate coherent Shakespearean-style text, preserving syntax and vocabulary style.
Streamlit-based interactive UI for real-time next-character or next-word predictions.
Includes example phrases from Shakespeare for immediate demonstration.
You can install the required packages using pip:
pip install -r requirements.txtClone the repository:
git clone https://github.com/anjaliy11/LSTM_RNN.git
cd LSTM_RNNInstall the dependencies:
pip install -r requirements.txtTo run the Streamlit application:
streamlit run app.pyThis command will start a local server, and you can interact with the model through your web browser.
- Model Architecture: LSTM-based neural network.
- Training Data: hamlet.txt
- Training Process: The model was trained to predict the next character in a sequence, capturing the stylistic elements of Shakespearean text.
Contributions are welcome! If you have suggestions for improvements or enhancements, please fork the repository and submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
For any inquiries or feedback, please contact anjaliy11.