Skip to main content

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

Quick Start

Binary Classification

import numpy as np
from NeuroSketch.engine.nn import Sequential, Linear
from NeuroSketch.engine.act import Sigmoid
from NeuroSketch.losses import BinaryCrossentropyLoss
from NeuroSketch.optims import Adam
from NeuroSketch.utils import DataLoader

# Create data
x = np.random.randn(100, 10)
y = np.random.randint(2, size=100)
loader = DataLoader(x, y, batch_size=16, shuffle=True)

# Create model
model = Sequential(
    Linear(in_features=10, out_features=1, init_type="he"),
    Sigmoid()
)
criterion = BinaryCrossentropyLoss(model.layers[-1])
optimizer = Adam(model, lr=0.01)

# Training loop
for epoch in range(10):
    for x_batch, y_batch in loader:
        # Forward
        pred = model(x_batch)
        loss = criterion(pred, y_batch)
        
        # Backward
        criterion.backward()
        
        # Update
        optimizer.step()

Multiclass Classification

from NeuroSketch.engine.nn import Sequential, Linear
from NeuroSketch.engine.act import Softmax
from NeuroSketch.losses import SparseCategoricalCrossentropyLoss
from NeuroSketch.optims import Adam
from NeuroSketch.utils import DataLoader

# Create model
model = Sequential(
    Linear(in_features=10, out_features=3, init_type="he"),
    Softmax()
)
criterion = SparseCategoricalCrossentropyLoss(model.layers[-1])
optimizer = Adam(model, lr=0.01)

# Train
loader = DataLoader(x, y, batch_size=16, shuffle=True)
for epoch in range(10):
    for x_batch, y_batch in loader:
        pred = model(x_batch)
        loss = criterion(pred, y_batch)
        criterion.backward()
        optimizer.step()

Architecture

NeuroSketch/
├── engine/
│   ├── nn.py         # Linear, Sequential
│   └── act.py        # All activations
├── losses.py         # Loss functions
├── optims.py         # Optimizers (SGD, Momentum, Adam)
└── utils.py          # DataLoader

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

neurosketch-0.1.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

neurosketch-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file neurosketch-0.1.1.tar.gz.

File metadata

  • Download URL: neurosketch-0.1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for neurosketch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c7fb0383e82105bf3af85e106ad8db2f8e12406294d0d2230933724c10356f42
MD5 8284218394e54ad658ccaa73b367c1e2
BLAKE2b-256 315b378d039c06019e39cf775dccc16e8f2d25e56b5ca7b8ad0d5ac4ed3d8753

See more details on using hashes here.

File details

Details for the file neurosketch-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: neurosketch-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for neurosketch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 38190e9f779d72450258716a4ef8c23502bc7e9a87b318e92463c10a1c577fe9
MD5 a22b74b7c49a18b7ca9022877c74b4bc
BLAKE2b-256 e072d0a405a47a26f1c92dfcd2144b12d868f6fe73409e5cee937c71d13e46e2

See more details on using hashes here.

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