A mini supervised learning framework
Project description
NeuroSketch
A lightweight supervised learning framework built from scratch with NumPy. No black boxes.
Implements fundamental ML concepts: linear layers, activations, loss functions, and optimizers with explicit gradient computation and backpropagation.
Features
Layers
- Linear - Fully connected layers with He/Xavier initialization
Activations
- ReLU, LeakyReLU, Sigmoid, Tanh, Softmax, Swish, HeavySide
Loss Functions
- MSELoss, MAELoss, BinaryCrossentropyLoss, SparseCategoricalCrossentropyLoss
Optimizers
- SGD, Momentum, Adam
Installation
pip install neurosketch
Or from source:
git clone <repo>
cd neurosketch
pip install -e .
Quick Start
Binary Classification
import numpy as np
from neurosketch.layers import Linear
from neurosketch.activations import Sigmoid
from neurosketch.losses import BinaryCrossentropyLoss
from neurosketch.optimizers import Adam
# Create model
linear = Linear(in_features=10, out_features=1, init_type="he")
activation = Sigmoid()
criterion = BinaryCrossentropyLoss(linear)
# Forward pass
x = np.random.randn(32, 10)
z = linear.forward(x)
pred = activation.forward(z)
loss = criterion(pred, y)
# Backward pass
criterion.backward()
# Optimize
optimizer = Adam(layers=[linear])
optimizer.step(learning_rate=0.01)
Multiclass Classification
from neurosketch.layers import Linear
from neurosketch.activations import Softmax
from neurosketch.losses import SparseCategoricalCrossentropyLoss
linear = Linear(in_features=10, out_features=3, init_type="xavier")
activation = Softmax()
criterion = SparseCategoricalCrossentropyLoss(linear)
z = linear.forward(x)
pred = activation.forward(z)
loss = criterion(pred, y)
criterion.backward()
Architecture
neurosketch/
├── layers/
│ └── linear.py
├── activations/
│ ├── relu.py
│ ├── sigmoid.py
│ ├── softmax.py
│ └── ...
├── losses/
│ ├── mse.py
│ ├── bce.py
│ └── sparse_cce.py
├── optimizers/
│ ├── gd.py
│ ├── sgd.py
│ └── adam.py
└── _module.py
Design
Each component handles its own gradient computation:
- Linear layer: Computes dW, db via matrix multiplication
- Activations: Apply element-wise or Jacobian-based gradient chaining
- Loss functions: Compute gradients w.r.t. predictions
- Optimizers: Update weights using accumulated gradients
Requirements
- Python 3.7+
- NumPy
License
MIT
Built from scratch to understand ML fundamentals.
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
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 neurosketch-0.1.0.tar.gz.
File metadata
- Download URL: neurosketch-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ff6e3fc5ee4d12a2450e5c0363080726a214b84e1974a55e5b915e38ca2e0a0
|
|
| MD5 |
23c60747e19111e9f1069c8ebd96e020
|
|
| BLAKE2b-256 |
693bab773f2012c895324679c19222b9b06a0b8d17256b7c7f9beda3ed0d509c
|
File details
Details for the file neurosketch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: neurosketch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eab730d3f89d2830f6b037bd8a241b31ed42772529187871d03a939ba40b86b3
|
|
| MD5 |
d0e16ee9b1bd1d6bf3defe025cc32d35
|
|
| BLAKE2b-256 |
951bd247183d202ac9017ac9d2c70b11b957b7cfa0c2b951b7dd97288e3287eb
|