You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
encoder.py contains the code for OpenAI's BPE Tokenizer, taken straight from their gpt-2 repo.
utils.py contains the code to download and load the GPT-2 model weights, tokenizer, and hyper-parameters.
gpt2.py contains the actual GPT model and generation code which we can run as a python script.
gpt2_pico.py is the same as gpt2.py, but in even fewer lines of code. Why? Because why not 😎👍.
Dependencies
pip install -r requirements.txt
Tested on Python 3.9.10.
Usage
python gpt2.py "Alan Turing theorized that computers would one day become"
Which generates
the most powerful machines on the planet.
The computer is a machine that can perform complex calculations, and it can perform these calculations in a way that is very similar to the human brain.
You can also control the number of tokens to generate, the model size (one of ["124M", "355M", "774M", "1558M"]), and the directory to save the models:
python gpt2.py \
"Alan Turing theorized that computers would one day become" \
--n_tokens_to_generate 40 \
--model_size "124M" \
--models_dir "models"
About
An unnecessarily tiny implementation of GPT-2 in NumPy.