Skip to content

Text generation using a Recurrent Neural Network (RNN) in PyTorch. This project demonstrates how to train an RNN model to learn and generate text based on a training corpus, allowing for the creation of text sequences in the style of the source dataset.

License

Notifications You must be signed in to change notification settings

joseg20/rnn-text-generation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rnn-text-generation

This project uses a Recurrent Neural Network (RNN) to generate text based on a training corpus. The model is trained on characters rather than words, allowing for greater flexibility in text generation.

Run Locally

Clone the project

  git clone https://github.com/joseg20/rnn-text-generation

Go to the project directory

  cd rnn-text-generation

Install requirements

  pip install -r requirements.txt

Go to the source directory

  cd rnn-text-generation/src

Prepare your training data in a text file (e.g., data/corpus.txt).

Train the model:

  python main.py --data data/corpus.txt --epochs 10

This will train the model on the specified text file and save the trained model in models/trained_rnn_model.pth.

Generate text using the trained model:

  python main.py --generate --seed_text "Once upon a time" --model_path ../models/trained_rnn_model.pth

This will generate text using the trained model and the seed text "Once upon a time".

Usage

You can customize the training and generation process by adjusting the arguments in main.py. Some of the available arguments include:

  • --data: Path to the text file for training.
  • --model_path: Path to the trained model.
  • --epochs: Number of training epochs.
  • --generate: Generate text instead of training a new model.
  • --seed_text: Seed text for generating text.

Refer to main.py for more options and details on how to adjust the model's hyperparameters.

Contributing

Contributions are welcome. Please feel free to open an issue or a pull request if you find any bugs or have suggestions for improvements.

Authors

License

MIT

About

Text generation using a Recurrent Neural Network (RNN) in PyTorch. This project demonstrates how to train an RNN model to learn and generate text based on a training corpus, allowing for the creation of text sequences in the style of the source dataset.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages