A 10M parameter decoder-only transformer trained on the Tiny Shakespeare dataset. Built from scratch in PyTorch as an educational project — no pretrained weights or external libraries used for the model itself.
Model Description
Architecture: Decoder-only transformer with modern components (RMSNorm, SwiGLU, RoPE, KV cache)
Early stopping was used — the model checkpointed at the lowest validation loss.
Component Comparison
Each modern component was tested in isolation against the vanilla baseline (2,000 training steps each):
Component
Val Loss at Step 500
vs Vanilla
Vanilla (baseline)
1.99
—
RMSNorm
1.99
No change
SwiGLU
1.88
-0.11
RoPE
1.68
-0.31
Intended Use
This is an educational model. It is not intended for production use. It generates Shakespeare-style text and serves as a reference implementation for understanding transformer architectures.
Sample Outputs
Modern model, prompt: "ROMEO:", temperature=0.8:
ROMEO:
A gallant-house! what says the woe?
MERCUTIO:
Good madam, my lord.
ROMEO:
Villain, for I do not say it is true,
Which hath a sin by him come to the crown,
That he is reports for me; for ever is he.
Vanilla model, prompt: "ROMEO:", temperature=0.8:
ROMEO:
Good father, cousin, my lord, I could not need me.
First Servant:
Sir, but you came to this humour of the king,
Lest hear him withis heart flowers.
Limitations
Tiny dataset: Trained on only 1.1MB of text. The model overfits after ~2,500 steps.
Character-level tokenization: Inefficient compared to BPE. Each character is a separate token.
No instruction tuning: This is a base model — it completes text, it does not follow instructions or answer questions.
Small context window: 256 tokens maximum.
Quality: Output is recognizably Shakespeare-like but contains grammatical errors and occasionally mixes characters from different plays.