How nageshram/gptfromscratch works
This repository trains a character-level decoder-only GPT on input.txt, evaluates training and validation loss, saves a checkpoint, and can generate text later from that checkpoint. The main path runs from corpus encoding through batched optimization and evaluation to checkpointed inference. The model’s attention, feed-forward, and transformer-block relationships are visible in the excerpts; README statements support the broader training and hardware capabilities. Some training-loop and device-selection details were not sampled, so those connections are documented rather than inferred from unseen code.
Main entry points: bigram.py Training and evaluation · sample.py Checkpoint inference · input.txt Training corpus
Components 15
Data and training
- Training corpus
input.txt - Character encoding
bigram.py - Train and val batches
bigram.py - Training and evaluation
bigram.py - AdamW optimizer
bigram.py - Compute device
bigram.py
Transformer model
- Language model
bigram.py - Causal attention
bigram.py - Feed-forward network
bigram.py - Transformer block
bigram.py
Checkpoint and generation
- Model checkpoint
bigram.py - Checkpoint inference
sample.py - Text generation
bigram.py - Generated text
Other components
- User
Connections 17
- User → Training and evaluation: starts training
README.md - Training corpus → Character encoding: provides text
bigram.py - Character encoding → Train and val batches: encodes characters
README.md - Train and val batches → Training and evaluation: supplies batches
README.md - Training and evaluation → Language model: trains and evaluates
README.md - Training and evaluation → AdamW optimizer: updates with
README.md - Training and evaluation → Model checkpoint: saves weights and metadata
bigram.py - Language model → Transformer block: applies stacked blocks
bigram.py - Transformer block → Causal attention: invokes
bigram.py - Transformer block → Feed-forward network: invokes
bigram.py - Training and evaluation → Compute device: selects hardware
README.md - User → Checkpoint inference: runs inference
README.md - Checkpoint inference → Model checkpoint: loads
sample.py - Checkpoint inference → Language model: instantiates and restores
sample.py - Checkpoint inference → Text generation: requests generation
sample.py - Text generation → Language model: calls autoregressively
bigram.py - Text generation → Generated text: decodes characters