Skip to main content

A minimal scalar-valued autograd engine with neural network primitives, built for learning purposes.

Project description

learngrad

A minimal scalar-valued autograd engine with neural network primitives, built for learning purposes. Inspired by micrograd.

Install

pip install learngrad

What's inside

  • Value — scalar with automatic differentiation via backprop
  • MLP — multi-layer perceptron built on top of Value
  • OptimizersSGD, SGDMomentum, RMSProp, Adam

Quick example

from learngrad.engine import Value
from learngrad.nn import  MLP
from learngrad.optimizers import Adam

# Autograd
x = Value(2.0)
y = x ** 2 + x * 3
y.backward()
print(x.grad)  # dy/dx = 2x + 3 = 7.0

# Neural net
model = MLP(2, [4, 4, 1])
opt = Adam(model.parameters(), lr=1e-3)

x = [Value(1.0), Value(0.5)]
out = model(x)
out.backward()
opt.step()

Demo

notebooks/demo.ipynb walks through a full training example:

  • Binary classification on the make_circles dataset
  • MLP with hinge loss and L2 regularization
  • Mini-batch training loop with Adam
  • Train/val accuracy tracking
  • Decision boundary visualization

Reaches ~94% val accuracy in 100 epochs.

Requirements

  • Python >= 3.10
  • numpy

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

learngrad-0.2.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

learngrad-0.2.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file learngrad-0.2.1.tar.gz.

File metadata

  • Download URL: learngrad-0.2.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for learngrad-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2dddb157f1c1c4a96099a4c4c1bc75f2e1145b1c0b019c10f70832c34ca9b731
MD5 7af342669ddd0b1229835b5f02821127
BLAKE2b-256 a04b772d34eba751a9a24c9f92b4b109739bb430f191d0a9417b2ff3204e89fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for learngrad-0.2.1.tar.gz:

Publisher: publish.yml on devparikh0506/learngrad

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

File details

Details for the file learngrad-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: learngrad-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for learngrad-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1126e6971fceef3809897bfc785eb3ff69f1c69c4a25a916b3e4b1d641a09ea5
MD5 c0221673c94e4c2588f14306db4164e6
BLAKE2b-256 3d5cab215ff6325f53892edcf2077b2e5ad68e9bbd674b9ac3675ab9e7c6c8fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for learngrad-0.2.1-py3-none-any.whl:

Publisher: publish.yml on devparikh0506/learngrad

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