Feedback: (mentor-to-mentor)
This repo does something very few juniors ever experience:
It lets them touch the architecture, not just tune knobs on top of it.
GPT-PLAY is a tiny, runnable GPT-style Transformer project aimed at juniors for learning, not benchmarking.
The goal is simple:
- Understand the Transformer architecture
- Understand datasets
- Run it
- Train it
- See text come out
- Change things and observe what breaks or improves
This is NOT about fine-tuning large models. This is about understanding what a GPT actually is.
- A minimal decoder-only Transformer (GPT-style)
- Character-level language modeling
- Train-from-scratch on a tiny text file
- Fully readable, hackable code
- No frameworks, no abstractions, no hidden magic
If you can run this, you understand more than most people who say "I fine-tuned a model".
- Python 3.9+
- PyTorch 2.x (CPU is fine)
Install PyTorch (CPU example):
pip install torch
-
Put any text you like into input.txt (a README, a story, logs, anything)
-
Run:
python play.py
-
Watch:
- Loss go down
- Text slowly start to make sense
Open play.py and gpt.py and experiment:
- Change num_layers
- Change num_heads
- Change embedding size
- Change block_size
- Change learning rate
- Break it and fix it
This is how understanding is built.
This model will NOT produce good text. That is not the point.
The point is:
- Architecture over tooling
- Understanding over scale
- Learning how GPTs actually work
To make GPT-PLAY educational, we've included a tiny, highly predictable dataset in input.txt. This dataset is designed so that after a few hundred training steps, you will see the model start generating correct words and sequences.
- How repeated patterns in data help a model converge faster
- How small vocabulary and simple sequences make the model “memorize” effectively
- Why dataset quality and structure matter more than hyperparameter tuning at this stage
-
Ensure
input.txtcontains the example dataset (words and short sequences), for example:the cat
the dog
the fish
the bird
apple is red
banana is yellow
orange is orange
i like cats
i like dogs
... -
Run the training script:
python play.py
-
Observe output every 100–300 steps:
-
Initially, the model produces mostly gibberish
-
After ~500–1000 steps, you will start seeing sequences like:
the cat
the dog
apple is red
banana is yellow -
This shows convergence and how the model learns from repetitive patterns
- Experiment:
- Add new words or phrases to the dataset and re-run
- Observe how long it takes for the model to reproduce new sequences
- Try breaking patterns intentionally to see what happens
This exercise clearly demonstrates the importance of datasets in training:
- Even a tiny model can memorize predictable sequences
- Without repetition or structure, convergence is slow or incoherent
- Understanding what data you feed is just as important as how you train it
Educational playground. Safe to break. Encouraged to experiment.
