Skip to content
TerminayPublic

Repository files navigation

banner

Python PyPI License Tests CodeQL PyPI Publish Size Real Downloads Stars

Leanpass is a lightweight, transparent NumPy-based autodiff library for small neural network experiments. It is designed to be easy to read, simple to inspect, and practical for learning how automatic differentiation works under the hood.

Leanpass is indexed in the awesome-machine-learning repository, under the python section.

demo

I am incredibly grateful to the early contributors helping me shape this project! Click on their profiles below to follow them and check out their work:

Contributor Follow First PR
eeshsaxena Follow #18
VedantMadane Follow #40
Chirudeva-Reddy Follow #56
bh-official Follow #83

Made with contrib.rocks.

Want to help out? I am actively looking for fresh eyes to test features, fix bugs, or improve docs. Check out the open Issues or just open a PR.

Note

If your profile picture isn't showing up yet, Contrib.Rocks can take a few days to update due to high traffic.

Table of contents

Why LeanPass?

  • Minimal dependency footprint: only NumPy
  • Clear, readable implementation instead of heavy abstraction
  • Core building blocks for tensors, layers, and optimizers
  • Useful for teaching, prototyping, and small-scale experimentation

Features

  • Tensor objects with reverse-mode autodiff
  • Core arithmetic and matrix operations
  • Activation functions such as ReLU, sigmoid, softmax, tanh, LeakyReLU, and GELU
  • Linear layers and multilayer perceptrons
  • Loss utilities: mse_loss, cross_entropy_loss, and binary_cross_entropy_loss
  • SGD and Adam optimizers
  • SGD now supports momentum and L2 weight decay: optim.SGD(params, lr=..., momentum=0.9, weight_decay=1e-4)
  • Adam supports an optional L2 weight decay: optim.Adam(params, lr=..., weight_decay=1e-4)
  • Dropout layer: nn.Dropout(p=0.5) for inverted dropout during training
  • Tensor utilities: Tensor.clip(a_min, a_max) / Tensor.clamp(min, max) for value clamping
  • Basic indexing: Tensor.__getitem__ supports slicing/indexing that participates in autodiff
  • A simple demo script that trains a toy model

Installation

pip install leanpass

Documentation

Full documentation is available at leanpass.vercel.app and includes API reference, core concept explanations, and hands-on guides covering regression, classification, MNIST, gradient checking, and custom layers. See the changelog for the complete release history.

DeepWiki

To delve more into the development of leanpass, you could check out the devin indexed deepwiki docs. The deepwiki docs update 1 day later of every release or update made to leanpass, note that.

Ask DeepWiki

Quick start

When leanpass is installed, build a small neural network and run a forward pass:

from leanpass import Tensor, nn

x = Tensor([[1.0, 2.0]], requires_grad=False)
model = nn.MLP([2, 16, 3])
logits = model(x)
print(logits)

Examples

Explore runnable Python examples in examples/:

Example File Description
Classification examples/demo.py 3-class synthetic data with MLP
XOR examples/demo_xor.py Classic XOR problem with 2-layer network
MNIST-lite examples/demo_mnist_lite.py Digit classification on sklearn digits (8×8 images)
Regression examples/demo_regression.py Sine wave fitting with MLP

Run any example with:

python -m examples.demo                 # 3-class classification
python -m examples.demo_xor             # XOR classification
python -m examples.demo_mnist_lite      # MNIST-lite
python -m examples.demo_regression      # Regression

Development

Run the test suite from the repository root:

pytest

Project status

LeanPass is an actively maintained NumPy autodiff project for education and small-scale neural network experiments. The core API is stable; bug reports and documentation improvements are welcome.

Community and contribution

License

This project is licensed under the MIT License. See LICENSE for details.

Star History

Star History Chart

RepoVibes

RepoVibes

Releases

Used by

Contributors

Languages