How omarelghamry1/gpt-from-scratch works
This repository is a character-level GPT learning project: it trains on Tiny Shakespeare, evaluates next-character loss, and samples Shakespeare-like text. The main runnable workflow is gpt.py; Bigram.py provides a baseline, while the notebooks document the build and separate residual-network experiments. The source excerpts show the runnable scripts in detail; notebook capabilities and their dataset use are included as documented in the README, without inferring their internal flow.
Main entry points: gpt.py GPT model · gpt_from_scratch.ipynb GPT build walkthrough · Residual Network .ipynb Residual network experiments · input.txt Tiny Shakespeare
Components 18
Data preparation
- Tiny Shakespeare
input.txt - Names dataset
names.txt - Character encoding and splits
gpt.py - Batch sampling
gpt.py
Language models
- Bigram baseline
Bigram.py - GPT model
gpt.py - Token and position embeddings
gpt.py - Causal multi-head attention
gpt.py - Feed-forward network
gpt.py - Transformer residual block
gpt.py
Training and generation
- Next-character loss
gpt.py - Train and validation evaluation
gpt.py - AdamW training loop
gpt.py - Text generation
gpt.py - Generated text
Learning experiments
- GPT build walkthrough
gpt_from_scratch.ipynb - Residual network experiments
Residual Network .ipynb
Other components
- Project user
Connections 21
- Project user → GPT model: runs
README.md - Project user → Bigram baseline: runs baseline
README.md - Project user → GPT build walkthrough: explores
README.md - Project user → Residual network experiments: explores
README.md - Tiny Shakespeare → Character encoding and splits: read by
gpt.py - Character encoding and splits → Batch sampling: prepares
gpt.py - Batch sampling → GPT model: feeds
gpt.py - GPT model → Token and position embeddings: looks up
gpt.py - Token and position embeddings → Transformer residual block: feeds
gpt.py - Transformer residual block → Causal multi-head attention: applies
gpt.py - Transformer residual block → Feed-forward network: applies
gpt.py - GPT model → Next-character loss: computes
gpt.py - Batch sampling → Train and validation evaluation: supplies batches
gpt.py - Train and validation evaluation → GPT model: evaluates
gpt.py - AdamW training loop → Batch sampling: samples
gpt.py - AdamW training loop → GPT model: trains
gpt.py - AdamW training loop → Next-character loss: backpropagates
gpt.py - GPT model → Text generation: provides model
gpt.py - Text generation → Generated text: decodes
gpt.py - Names dataset → Residual network experiments: used by
README.md - GPT build walkthrough → GPT model: walks through
README.md