Skip to main content

A fully vectorized Deep Learning framework built from scratch using only NumPy.

Project description

MPNeuralNetwork Logo

MPNeuralNetwork 🧠

PyPI version Python Build Status License: MIT Documentation Status NumPy CuPy Ruff Checked with mypy

A fully vectorized Deep Learning framework built from scratch using only NumPy and CuPy.

📖 Read the Full Documentation

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:

  1. Mathematical Rigor: Implementing backpropagation, chain rule derivatives, and loss functions manually.
  2. Performance Optimization: Moving from naive scalar loops to fully vectorized matrix operations and implementing im2col for convolutions.
  3. 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 im2col for hardware acceleration.
  • GPU Acceleration: Seamless support for NVIDIA GPUs via CuPy. Switch backends with a single environment variable.
  • 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 .npz files.

👉 Learn more about the internal engine

Component Inventory

Category Available Components
Layers Dense, Convolutional, MaxPooling2D, AveragePooling2D, Dropout, BatchNormalization, Flatten
Activations ReLU, Sigmoid, Tanh, Softmax, PReLU, Swish
Optimizers SGD, RMSprop, AdamW
Losses MSE, BinaryCrossEntropy, CategoricalCrossEntropy

Installation

pip install mpneuralnetwork

Quick Start

MNIST Classification

import numpy as np
from sklearn.datasets import fetch_openml
from sklearn.preprocessing import OneHotEncoder
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. Load Data (MNIST)
X, y = fetch_openml('mnist_784', version=1, return_X_y=True, as_frame=False)
X = (X / 255.0).astype(np.float32) # Normalize & Float32
y = OneHotEncoder(sparse_output=False).fit_transform(y.reshape(-1, 1))

# 2. Define the Architecture
network = [
    Dense(128, input_size=784), # Auto-He Init
    ReLU(),
    Dropout(0.2),
    Dense(10)                   # Output Logits
]

# 3. Initialize
model = Model(
    layers=network,
    loss=CategoricalCrossEntropy(),
    optimizer=Adam(learning_rate=0.001)
)

# 4. Train (Auto-Validation Split)
model.train(X, y, epochs=5, batch_size=64, 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

The roadmap has been moved to our GitHub Project board.

Author

Maxime Pires - AI Engineer | CentraleSupelec

LinkedIn | Portfolio

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpneuralnetwork-1.2.0b1.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mpneuralnetwork-1.2.0b1-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file mpneuralnetwork-1.2.0b1.tar.gz.

File metadata

  • Download URL: mpneuralnetwork-1.2.0b1.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mpneuralnetwork-1.2.0b1.tar.gz
Algorithm Hash digest
SHA256 d628f848cc71d80cf1f70db6a4ed555ba14e73701b48cba0fdd8cd2383340703
MD5 82b19972a8f9ed6ec141d68b6ce20fca
BLAKE2b-256 865107eeb9033fed069c6fa9b753e3b48baebacfefda4c82ea23899fa81f0f37

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpneuralnetwork-1.2.0b1.tar.gz:

Publisher: ci_cd.yml on maximepires4/mp-neural-network

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mpneuralnetwork-1.2.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for mpneuralnetwork-1.2.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 511df4ae36c612773574c64477dfc78f995d0f95a319b1513108f87fc4bff8b1
MD5 1fd137403773b2a2f1f73a31c678a3f0
BLAKE2b-256 14f9f7b34e8063fe9cf49b37e67f4cc7f752972662fd735fbb9e5e5908daf68d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpneuralnetwork-1.2.0b1-py3-none-any.whl:

Publisher: ci_cd.yml on maximepires4/mp-neural-network

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page