# pantelis0/neural-network-from-scratch architecture

> Architecture diagram of the GitHub repository pantelis0/neural-network-from-scratch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pantelis0/neural-network-from-scratch
- Repository: https://github.com/pantelis0/neural-network-from-scratch
- Video tour (about a minute): https://gitdiagram.com/pantelis0/neural-network-from-scratch/video

## Overview

This is a NumPy handwritten-digit classifier. Its main workflow loads and normalizes MNIST/EMNIST data, trains a dense neural network with backpropagation and Adam, evaluates accuracy, and saves parameters; prediction scripts and a Tkinter drawing demo use the saved model. The graph also preserves the documented layer, activation, loss, and dataset stages. Edges are limited to relationships shown in the excerpts or README; unsampled plotting and other implementation details are not expanded.

Main entry points: [`train.py`](https://github.com/pantelis0/neural-network-from-scratch/blob/main/train.py) (Mini-batch training), [`network.py`](https://github.com/pantelis0/neural-network-from-scratch/blob/main/network.py) (Network forward/backward), [`predict.py`](https://github.com/pantelis0/neural-network-from-scratch/blob/main/predict.py) (Sample prediction), [`data_loader.py`](https://github.com/pantelis0/neural-network-from-scratch/blob/main/data_loader.py) (Dataset loading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_loader["Dataset loading<br/>[data_loader.py]"]
end

subgraph group_model["Network computation"]
  node_dense["Dense layers<br/>[layers.py]"]
  node_activations["Activations<br/>[activations.py]"]
  node_loss["Cross-entropy<br/>[losses.py]"]
  node_network["Network forward/backward<br/>[network.py]"]
end

subgraph group_training["Training and evaluation"]
  node_trainer["Mini-batch training<br/>[train.py]"]
  node_optimizer["Adam optimizer<br/>[optimizer.py]"]
  node_evaluation["Accuracy evaluation<br/>[train.py]"]
  node_model_store[("Saved parameters")]
end

subgraph group_inference["Prediction interfaces"]
  node_predict["Sample prediction<br/>[predict.py]"]
  node_drawing["Digit drawing demo<br/>[draw_demo.py]"]
end

node_user(("User"))
node_mnist[("MNIST source")]
node_emnist[("EMNIST dataset")]

node_user -->|"runs training"| node_trainer
node_user -->|"runs prediction"| node_predict
node_user -->|"draws digit"| node_drawing
node_mnist -->|"downloads data"| node_loader
node_emnist -->|"loads dataset"| node_loader
node_loader -->|"provides batches"| node_trainer
node_trainer -->|"runs passes"| node_network
node_trainer -->|"computes loss"| node_loss
node_trainer -->|"updates parameters"| node_optimizer
node_trainer -->|"evaluates model"| node_evaluation
node_network -->|"calls layers"| node_dense
node_network -->|"applies activations"| node_activations
node_network -->|"uses gradient"| node_loss
node_trainer -->|"saves parameters"| node_model_store
node_predict -->|"loads samples"| node_loader
node_predict -->|"loads parameters"| node_model_store
node_predict -->|"runs inference"| node_network
node_drawing -->|"loads parameters"| node_model_store
node_drawing -->|"runs inference"| node_network

click node_loader "https://github.com/pantelis0/neural-network-from-scratch/blob/main/data_loader.py"
click node_dense "https://github.com/pantelis0/neural-network-from-scratch/blob/main/layers.py"
click node_activations "https://github.com/pantelis0/neural-network-from-scratch/blob/main/activations.py"
click node_loss "https://github.com/pantelis0/neural-network-from-scratch/blob/main/losses.py"
click node_network "https://github.com/pantelis0/neural-network-from-scratch/blob/main/network.py"
click node_trainer "https://github.com/pantelis0/neural-network-from-scratch/blob/main/train.py"
click node_optimizer "https://github.com/pantelis0/neural-network-from-scratch/blob/main/optimizer.py"
click node_evaluation "https://github.com/pantelis0/neural-network-from-scratch/blob/main/train.py"
click node_model_store "https://github.com/pantelis0/neural-network-from-scratch/tree/main/saved_models"
click node_predict "https://github.com/pantelis0/neural-network-from-scratch/blob/main/predict.py"
click node_drawing "https://github.com/pantelis0/neural-network-from-scratch/blob/main/draw_demo.py"

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_loader,node_user toneBlue
class node_dense,node_activations,node_loss,node_network,node_mnist,node_emnist toneAmber
class node_trainer,node_optimizer,node_evaluation,node_model_store toneMint
class node_predict,node_drawing toneRose
```

## Components

### Data preparation

- [Dataset loading](https://github.com/pantelis0/neural-network-from-scratch/blob/main/data_loader.py): `data_loader.py`

### Network computation

- [Dense layers](https://github.com/pantelis0/neural-network-from-scratch/blob/main/layers.py): `layers.py`
- [Activations](https://github.com/pantelis0/neural-network-from-scratch/blob/main/activations.py): `activations.py`
- [Cross-entropy](https://github.com/pantelis0/neural-network-from-scratch/blob/main/losses.py): `losses.py`
- [Network forward/backward](https://github.com/pantelis0/neural-network-from-scratch/blob/main/network.py): `network.py`

### Training and evaluation

- [Mini-batch training](https://github.com/pantelis0/neural-network-from-scratch/blob/main/train.py): `train.py`
- [Adam optimizer](https://github.com/pantelis0/neural-network-from-scratch/blob/main/optimizer.py): `optimizer.py`
- [Accuracy evaluation](https://github.com/pantelis0/neural-network-from-scratch/blob/main/train.py): `train.py`
- [Saved parameters](https://github.com/pantelis0/neural-network-from-scratch/tree/main/saved_models): `saved_models`

### Prediction interfaces

- [Sample prediction](https://github.com/pantelis0/neural-network-from-scratch/blob/main/predict.py): `predict.py`
- [Digit drawing demo](https://github.com/pantelis0/neural-network-from-scratch/blob/main/draw_demo.py): `draw_demo.py`

### Other components

- **User**
- **MNIST source**
- **EMNIST dataset**

## Connections

- User → Mini-batch training: runs training (evidence: `README.md`)
- User → Sample prediction: runs prediction (evidence: `README.md`)
- User → Digit drawing demo: draws digit (evidence: `draw_demo.py`)
- MNIST source → Dataset loading: downloads data (evidence: `data_loader.py`)
- EMNIST dataset → Dataset loading: loads dataset (evidence: `data_loader.py`)
- Dataset loading → Mini-batch training: provides batches (evidence: `train.py`)
- Mini-batch training → Network forward/backward: runs passes (evidence: `train.py`)
- Mini-batch training → Cross-entropy: computes loss (evidence: `train.py`)
- Mini-batch training → Adam optimizer: updates parameters (evidence: `train.py`)
- Mini-batch training → Accuracy evaluation: evaluates model (evidence: `train.py`)
- Network forward/backward → Dense layers: calls layers (evidence: `network.py`)
- Network forward/backward → Activations: applies activations (evidence: `network.py`)
- Network forward/backward → Cross-entropy: uses gradient (evidence: `network.py`)
- Mini-batch training → Saved parameters: saves parameters (evidence: `train.py`)
- Sample prediction → Dataset loading: loads samples (evidence: `predict.py`)
- Sample prediction → Saved parameters: loads parameters (evidence: `predict.py`)
- Sample prediction → Network forward/backward: runs inference (evidence: `predict.py`)
- Digit drawing demo → Saved parameters: loads parameters (evidence: `draw_demo.py`)
- Digit drawing demo → Network forward/backward: runs inference (evidence: `draw_demo.py`)
