A learning repo that implements core ML / DL building blocks from scratch (mostly NumPy-only), with step-by-step notebooks that explain the math, shapes, and backprop.
- Implement foundational components without using PyTorch / torch or high-level deep learning APIs.
- Keep code readable and inspectable (explicit intermediate variables > clever tricks).
- Provide playground notebooks that explain each module/architecture step-by-step.
- Include small runnable tests / scripts (CPU-friendly) to validate correctness.
-
DNN/ — Dense layer, activations, losses, and optimizers (NumPy)
Neuron.py,activation_functions.py,loss_functions.py,optimizers.pyplayground.ipynb
-
CNN/ — Convolutional building blocks (NumPy)
layers.py:Layer_Conv2D_Im2Col,Layer_MaxPool2D,Layer_Flattenplayground.ipynb
-
BatchNorm/ — Batch Normalization (NumPy)
batchnorm.py+test_batchnorm.pyplayground.ipynb
-
LayerNorm/ — Layer Normalization (NumPy)
layernorm.py+test_layernorm.pyplayground.ipynb
-
ResNet/ — ResNet-18 style network for MNIST built from this repo’s CNN + DNN blocks (NumPy)
resnet18_numpy.py,mnist_data.py,train_mnist.py,test_resnet_smoke.pyplayground.ipynb
-
Attention/ — attention walkthrough notebook(s)
- Install Python (3.10+ recommended) and Jupyter.
- Clone:
git clone https://github.com/sssstf0rest/Machine-Learning-Concepts-With-Code.git cd Machine-Learning-Concepts-With-Code - Start Jupyter and open any
playground.ipynb:jupyter notebook
Create a virtual environment (recommended) and install NumPy:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip numpyThen run:
python -m BatchNorm.test_batchnorm
python -m LayerNorm.test_layernorm
python -m ResNet.test_resnet_smokepython -m ResNet.train_mnist --epochs 1 --subset 5000 --batch-size 64 --lr 1e-3Notes:
- Full MNIST training with a ResNet-18 style model in pure NumPy can be slow; use
--subsetfor iteration.
Across the repo, layers generally follow:
forward(inputs)sets.outputbackward(dvalues)sets.dinputsand parameter gradients (e.g.,.dweights,.dbiases) when applicable
This makes it easy to compose layers and reuse optimizers.
If you add new concepts:
- include a
playground.ipynbexplaining the math + structure - add at least one small test / sanity script
- keep dependencies minimal
MIT