This project is a Shakespearean-style text generator using N-grams (bigrams, trigrams, or four-grams). The model is trained on Shakespeare's complete works from Project Gutenberg.
- Loads and tokenizes Shakespeare’s works from a manually downloaded text file.
- Uses an N-gram model to generate Shakespeare-like sentences.
- Allows the user to select the N-gram size (2, 3, or 4).
- Outputs a random Shakespearean-style text sample.
git clone https://github.com/YOUR_USERNAME/NLP-Text-Generator.git
cd NLP-Text-Generatorpython3 -m venv venv
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On Windowspip install -r requirements.txtManually download Shakespeare’s full works:
mkdir -p nltk_data/corpora/shakespeare
curl -o nltk_data/corpora/shakespeare/shakespeare.txt https://www.gutenberg.org/cache/epub/100/pg100.txtRun the program:
python main.pyFollow the prompts to select an N-gram size (2, 3, or 4), and the script will generate a text sample.
Enter the n-gram size (2, 3, 4): 3
Generating text with 3-grams:
Generated Text: womanhood. think, we are convented upon a wretch whose natural gifts were poor and speech unable; beyond all talents. whilst i go to ’t well, protect yourself. king henry...
NLP-Text-Generator/
│-- src/
│ │-- ngram_model.py # Handles text processing & N-gram logic
│-- data/
│ │-- shakespeare.txt # Downloaded Shakespeare text
│-- main.py # Runs the text generator
│-- tests/
│ │-- test_ngram.py # Unit tests
│-- requirements.txt # Dependencies
│-- README.md # Documentation
python -m unittest discover tests/- Convert the project into a web app using Flask.
- Train a deep learning model (LSTM or GPT-2) instead of N-grams.
- Improve punctuation handling and sentence coherence.
- Deploy as a Shakespearean chatbot!
MIT License.
🚀 Created by Anthony-Lee Sánchez