This project implements and compares three different sequential deep learning models for text generation: RNN, LSTM, and Transformer. The models are trained on a small text dataset from Project Gutenberg and evaluated using perplexity and BLEU scores.
data/: Contains raw and processed dataraw/: Raw text files from Project Gutenbergprocessed/: Processed data files (train.jsonl, test.jsonl)models/: Saved tokenizer models
src/: Source codedata_processing/: Data loading and tokenizationmodels/: Model implementationstraining/: Training functionalityevaluation/: Evaluation metricsvisualization/: Plotting and visualization
outputs/: Generated outputsmodels/: Saved model checkpointsfigures/: Generated plotsresults/: Evaluation results
- Clone the repository
- Install the required packages: pip install -r requirements.txt
Place your raw text files in the data/raw/ directory
Ensure train.jsonl and test.jsonl files are in the data/processed/ directory
python main.py --train_tokenizer
To train a specific model:
# Train the RNN model
python main.py --train_rnn
# Train the LSTM model
python main.py --train_lstm
# Train the Transformer model
python main.py --train_transformerTo train all three models sequentially:
python main.py --train_rnn --train_lstm --train_transformerTo evaluate a specific model:
# Evaluate the RNN model
python main.py --eval_rnn
# Evaluate the LSTM model
python main.py --eval_lstm
# Evaluate the Transformer model
python main.py --eval_transformerTo evaluate all models and compare their performance:
python main.py --eval_rnn --eval_lstm --eval_transformer --evaluate --custom_prompt "Your custom prompt here"You can customize the prompt by changing the text inside the quotes.
python main.py
- RNN: A vanilla RNN-based language model
- LSTM: An LSTM-based language model
- Transformer: A Transformer-based language model
- Perplexity (PPL): Measures how well the model predicts the next word
- BLEU Score: Compares generated text against ground truth sentences
Plots and evaluation results will be saved in the outputs/ directory.