# tanmay-boop-hash/soc-2025_building_llms_from_scratch architecture

> Architecture diagram of the GitHub repository tanmay-boop-hash/soc-2025_building_llms_from_scratch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch
- Repository: https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch

## Overview

This repository is a guided, notebook-based course project for building a GPT-style language model in Python and PyTorch. A learner progresses from programming and transformer concepts through preprocessing, attention, model assembly, training, pretrained-weight loading, and fine-tuning, ending with an instruction-tuned model and evaluation. The README documents the major stages; the sampled source shows the GPT-2 download and checkpoint-loading helper. Notebook internals beyond that sample are not verified, so documented connections are cited to the README.

Main entry points: [`gpt_download3.py`](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/gpt_download3.py) (GPT-2 weight loading), [`Week 5 + week 6 + week 7.ipynb`](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb) (Pretraining pipeline), [`01-python-variables-types-and-basic-io (1).ipynb`](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/01-python-variables-types-and-basic-io%20(1).ipynb) (Python basics), [`04-numpy (1).ipynb`](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/04-numpy%20(1).ipynb) (NumPy basics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_foundations["Foundations"]
  node_basics["Python basics"]
  node_numpy["NumPy basics<br/>[04-numpy &#40;1&#41;.ipynb]"]
  node_transformer_intro["Transformer concepts"]
end

subgraph group_model["Model construction"]
  node_preprocessing["Text preprocessing<br/>[week2.ipynb]"]
  node_attention["Attention mechanisms<br/>[week3.ipynb]"]
  node_transformer_block["Transformer block<br/>[week4 &#40;1&#41;.ipynb]"]
  node_combined["Combined implementation"]
end

subgraph group_training["Training and adaptation"]
  node_pretraining["Pretraining pipeline"]
  node_decoding["Text decoding"]
  node_finetuning["Task fine-tuning"]
  node_spam_classifier["Spam classifier"]
  node_instruction_tuning["Instruction tuning"]
  node_evaluation["LLM-judge evaluation"]
end

subgraph group_support["Model support"]
  node_weight_loading["GPT-2 weight loading<br/>[gpt_download3.py]"]
end

node_learner(("Learner"))
node_gpt2_host["GPT-2 file host"]

node_learner -->|"starts with"| node_basics
node_learner -->|"studies"| node_transformer_intro
node_basics -->|"builds foundations"| node_numpy
node_numpy -->|"continues into"| node_preprocessing
node_preprocessing -->|"precedes"| node_attention
node_attention -->|"feeds into"| node_transformer_block
node_transformer_block -->|"precedes"| node_pretraining
node_pretraining -->|"explores"| node_decoding
node_pretraining -->|"loads pretrained weights"| node_weight_loading
node_weight_loading -->|"downloads files"| node_gpt2_host
node_weight_loading -->|"provides model weights"| node_finetuning
node_finetuning -->|"culminates in"| node_spam_classifier
node_finetuning -->|"continues to"| node_instruction_tuning
node_instruction_tuning -->|"evaluates with"| node_evaluation
node_combined -->|"uses helper"| node_weight_loading

click node_basics "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/01-python-variables-types-and-basic-io%20(1).ipynb"
click node_numpy "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/04-numpy%20(1).ipynb"
click node_transformer_intro "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb"
click node_preprocessing "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/week2.ipynb"
click node_attention "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/week3.ipynb"
click node_transformer_block "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/week4%20(1).ipynb"
click node_combined "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/combined_code.ipynb"
click node_pretraining "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb"
click node_decoding "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb"
click node_weight_loading "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/gpt_download3.py"
click node_finetuning "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb"
click node_spam_classifier "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb"
click node_instruction_tuning "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb"
click node_evaluation "https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_basics,node_numpy,node_transformer_intro toneBlue
class node_preprocessing,node_attention,node_transformer_block,node_combined toneAmber
class node_pretraining,node_decoding,node_finetuning,node_spam_classifier,node_instruction_tuning,node_evaluation toneMint
class node_weight_loading toneRose
class node_learner,node_gpt2_host toneIndigo
```

## Components

### Foundations

- [Python basics](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/01-python-variables-types-and-basic-io%20(1).ipynb): `01-python-variables-types-and-basic-io (1).ipynb`
- [NumPy basics](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/04-numpy%20(1).ipynb): `04-numpy (1).ipynb`
- [Transformer concepts](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb): `Week 5 + week 6 + week 7.ipynb`

### Model construction

- [Text preprocessing](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/week2.ipynb): `week2.ipynb`
- [Attention mechanisms](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/week3.ipynb): `week3.ipynb`
- [Transformer block](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/week4%20(1).ipynb): `week4 (1).ipynb`
- [Combined implementation](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/combined_code.ipynb): `combined_code.ipynb`

### Training and adaptation

- [Pretraining pipeline](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb): `Week 5 + week 6 + week 7.ipynb`
- [Text decoding](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb): `Week 5 + week 6 + week 7.ipynb`
- [Task fine-tuning](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb): `Week 5 + week 6 + week 7.ipynb`
- [Spam classifier](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb): `Week 5 + week 6 + week 7.ipynb`
- [Instruction tuning](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb): `Week 5 + week 6 + week 7.ipynb`
- [LLM-judge evaluation](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/Week%205%20%2B%20week%206%20%2B%20week%207.ipynb): `Week 5 + week 6 + week 7.ipynb`

### Model support

- [GPT-2 weight loading](https://github.com/tanmay-boop-hash/soc-2025_building_llms_from_scratch/blob/main/gpt_download3.py): `gpt_download3.py`

### Other components

- **Learner**
- **GPT-2 file host**

## Connections

- Learner → Python basics: starts with (evidence: `README.md`)
- Learner → Transformer concepts: studies (evidence: `README.md`)
- Python basics → NumPy basics: builds foundations (evidence: `README.md`)
- NumPy basics → Text preprocessing: continues into (evidence: `README.md`)
- Text preprocessing → Attention mechanisms: precedes (evidence: `README.md`)
- Attention mechanisms → Transformer block: feeds into (evidence: `README.md`)
- Transformer block → Pretraining pipeline: precedes (evidence: `README.md`)
- Pretraining pipeline → Text decoding: explores (evidence: `README.md`)
- Pretraining pipeline → GPT-2 weight loading: loads pretrained weights (evidence: `README.md`)
- GPT-2 weight loading → GPT-2 file host: downloads files (evidence: `gpt_download3.py`)
- GPT-2 weight loading → Task fine-tuning: provides model weights (evidence: `README.md`)
- Task fine-tuning → Spam classifier: culminates in (evidence: `README.md`)
- Task fine-tuning → Instruction tuning: continues to (evidence: `README.md`)
- Instruction tuning → LLM-judge evaluation: evaluates with (evidence: `README.md`)
- Combined implementation → GPT-2 weight loading: uses helper (evidence: `README.md`)
