A tiny character-level GPT trained on Shakespeare's works. Runs entirely on CPU.
- Parameters: 0.83M
- Architecture: 4-layer transformer, 4 attention heads, 128-dim embeddings
- Vocabulary: 93 characters (ASCII/printable)
- Context length: 128 characters
- Training: CPU-only, ~5000 steps on 1.5M chars
# Basic generation
python3 generate.py --prompt "To be, or not" --max-tokens 200
# More creative (higher temperature)
python3 generate.py --prompt "Romeo, Romeo" --temperature 1.0 --max-tokens 300
# More focused (lower temperature)
python3 generate.py --prompt "good" --temperature 0.7 --max-tokens 150python3 generate.py --web --port 8081
# Open browser to http://localhost:8081train.py— train the model from scratchgenerate.py— standalone generator with CLI + web UImodel.pt— trained weightstokenizer.json— character mappingsinput.txt— training dataset
- Prompting: Start with Shakespeare-style phrases:
"To be, or not","Romeo, Romeo","The lady doth" - Generation style: Better with phrases longer than a few characters
- Sampling:
top_k=80andtemperature=0.8work well - CPU performance: Generation is instant for short sequences; 200+ tokens is still fast on modern CPUs
- Limitations: This is a toy model; it captures word patterns and rhythm, but not full grammar
# 1. Ensure dataset exists
python3 train.py # downloads Shakespeare if missing
# 2. Train (takes ~5-10 minutes on CPU)
python3 train.py
# 3. Generate
python3 generate.py --prompt "good"Try:
"What light through yonder window breaks""To die, to sleep""Friends, Romans, countrymen""The course of true love never did run smooth"