A fully vectorized Deep Learning framework built from scratch using only NumPy.
Project description
MPNeuralNetwork 🧠
A fully vectorized Deep Learning framework built from scratch using only NumPy.
Philosophy & Goal
In an era of high-level frameworks like PyTorch or TensorFlow, it is easy to treat Neural Networks as "black boxes".
MPNeuralNetwork is an engineering initiative designed to demystify the underlying mathematics of Deep Learning. By rebuilding the engine from the ground up, I aimed to bridge the gap between theoretical equations and production-grade code.
Key Objectives:
- Mathematical Rigor: Implementing backpropagation, chain rule derivatives, and loss functions manually.
- Performance Optimization: Moving from naive scalar loops to fully vectorized matrix operations and implementing
im2colfor convolutions. - Software Architecture: Applying SOLID principles for a modular design.
Key Features
MPNeuralNetwork goes beyond basic matrix operations by incorporating an "intelligent" engine.
- Fully Vectorized: Optimized for batch processing. Convolutions use
im2colfor hardware acceleration. - Early Stopping & Checkpointing: Automatically monitors validation loss and restores the best weights.
- Smart Initialization: Automatically applies He Init (for ReLU) or Xavier (for Sigmoid/Tanh).
- Comprehensive Regularization: Supports Dropout, L1/L2 Weight Decay (AdamW style).
- Numerical Stability: Internally handles logits for Softmax/Sigmoid to prevent overflow.
- Full Serialization: Save/Load model state to
.npzfiles.
👉 Learn more about the internal engine
Installation
pip install mpneuralnetwork
Quick Start
MNIST Classification
from mpneuralnetwork.layers import Dense, Dropout
from mpneuralnetwork.activations import ReLU
from mpneuralnetwork.losses import CategoricalCrossEntropy
from mpneuralnetwork.optimizers import Adam
from mpneuralnetwork.model import Model
# 1. Define the Architecture
network = [
Dense(128, input_size=784), # Auto-He Init
ReLU(),
Dropout(0.2),
Dense(10) # Output Logits
]
# 2. Initialize
model = Model(
layers=network,
loss=CategoricalCrossEntropy(),
optimizer=Adam(learning_rate=0.001)
)
# 3. Train (Auto-Validation Split)
model.train(X_train, y_train, epochs=10, batch_size=32, auto_evaluation=0.2)
👉 See full tutorials in the User Guide
Architecture & Performance
Vectorization
The training loop handles 3D/2D tensors, replacing slow Python loops with NumPy's BLAS routines. Convolutional layers use the im2col technique, transforming convolutions into efficient Matrix Multiplications (GEMM).
Optimization
The framework enforces Float32 precision globally to halve memory usage and double bandwidth. Recent benchmarks show a 26% speedup and 50% memory reduction compared to the initial implementation.
👉 Read the Optimization & Benchmarking Guide
Roadmap
Author
Maxime Pires - AI Engineer | CentraleSupelec
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mpneuralnetwork-1.1.0.tar.gz.
File metadata
- Download URL: mpneuralnetwork-1.1.0.tar.gz
- Upload date:
- Size: 38.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0af6e9501ab6d755923b0f6ad001230ad3c5393636236378c4280e282a87ce48
|
|
| MD5 |
5db1ec42bfd022f40a41a98aeb3f153f
|
|
| BLAKE2b-256 |
a7710933acac8226f685f56fae8e50078cace005ebf89a059a2f48139350746d
|
File details
Details for the file mpneuralnetwork-1.1.0-py3-none-any.whl.
File metadata
- Download URL: mpneuralnetwork-1.1.0-py3-none-any.whl
- Upload date:
- Size: 30.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f664491aa6ebb477edb67110f03d21d649d581a01cf138ed544e5edf47ad17b
|
|
| MD5 |
d35fe297dd5d24e13fd06965afcbdfcf
|
|
| BLAKE2b-256 |
21516d721a356f2d7a0d2ba69649da151ce996487ab750e3eac38008eb86b069
|