This project explores text generation using LSTM (Long Short-Term Memory) neural networks. It trains an LSTM model on a dataset of Medium article titles to predict the next word in a sequence, allowing for the generation of new text based on a seed text.
-
Clone the repository:
git clone https://github.com/selcia25/text-generation-using-lstm.git
-
Install the required libraries:
pip install pandas numpy tensorflow matplotlib
The dataset used for training the model is a collection of Medium article titles. The dataset (medium_data.csv
) contains a multiple columns including title
with the titles of the articles.
-
Preprocess the data: Clean the text by removing unnecessary characters and tokenize the text using the
Tokenizer
class from Keras. -
Generate input sequences: Create input sequences of varying lengths to train the model.
-
Pad sequences: Pad the input sequences to ensure uniform length.
-
Build the LSTM model: Construct a Sequential model with an Embedding layer, a Bidirectional LSTM layer, and a Dense output layer with a softmax activation.
-
Compile the model: Compile the model using the Adam optimizer and categorical crossentropy loss function.
-
Train the model: Train the model on the input sequences and corresponding labels.
-
Run the script to train the model.
-
Use the trained model to generate text by providing a seed text and specifying the number of words to generate.
Here are some examples of generating text using the trained model:
- Seed text: "implementation of"
- Generated text: "implementation of rnn lstm"
Contributions are welcome! Please fork the repository and create a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.