henesduran/GPT2-from-scratch ? reverse-engineered prompt
Reverse engineered prompt
Build me a GPT 2 style language model in PyTorch from scratch, with a clean, readable codebase that shows how the pieces fit together.
I want it to include token and positional embeddings, causal self attention, transformer blocks, and tied input and output embeddings, so I can train it on text and generate new text from a prompt. Please include a data prep script that can take a Hugging Face dataset, tokenize it with the GPT 2 encoding, and save it into training shards, plus a training script with checkpoint saving, gradient accumulation, learning rate scheduling, and mixed precision if available.
Also add a simple inference script where I can load a checkpoint and generate several samples from a prompt using top K sampling. If you need to look up current PyTorch or dataset docs online, go ahead and do that. Keep the default setup close to a small GPT 2 style model and make the project easy to run with a few commands.
Are you gonna build this?
make sure you review the code using coderabbit