Skip to main content

A lightweight, transparent alternative to PyTorch/TensorFlow built on NumPy.

Project description

LeanPass

LeanPass is a lightweight NumPy-based autodiff library for building small neural network models and understanding automatic differentiation in a simple, readable way.

Public API

Tensor

The core data structure is Tensor, which wraps a NumPy array and supports automatic differentiation.

from leanpass import Tensor

x = Tensor([[1.0, 2.0]], requires_grad=False)
y = Tensor([[3.0, 4.0]])
z = x + y

Supported operations:

  • Tensor + Tensor
  • Tensor - Tensor
  • Tensor * Tensor
  • Tensor / Tensor
  • Tensor ** Tensor
  • Tensor @ Tensor
  • Tensor.sum()
  • Tensor.mean()
  • Tensor.relu()
  • Tensor.sigmoid()
  • Tensor.tanh()
  • Tensor.leaky_relu()
  • Tensor.gelu()
  • Tensor.softmax()
  • Tensor.backward()

Neural network layers

from leanpass import nn

layer = nn.Linear(4, 8)
mlp = nn.MLP([4, 16, 8])

Available components:

  • nn.Linear(in_features, out_features) creates a linear layer with weights and bias.
  • nn.MLP(layer_sizes) creates a multilayer perceptron with ReLU activations between layers.
  • nn.mse_loss(predictions, targets) computes mean squared error.
  • nn.cross_entropy_loss(predictions, targets) computes categorical cross-entropy for multi-class targets.
  • nn.binary_cross_entropy_loss(predictions, targets) computes binary cross-entropy for binary classification.

Optimizers

from leanpass import optim

optimizer = optim.SGD(model.parameters(), lr=0.01)
# or
optimizer = optim.Adam(model.parameters(), lr=0.001)

Available optimizers:

  • optim.SGD(parameters, lr=...) performs simple gradient descent.
  • optim.Adam(parameters, lr=...) performs Adam optimization with bias correction.

Example

from leanpass import Tensor, nn, optim

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

Notes

This package is intended for clarity and educational use, with a compact implementation that makes the autodiff process easier to inspect.

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

leanpass-0.1.4.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

leanpass-0.1.4-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file leanpass-0.1.4.tar.gz.

File metadata

  • Download URL: leanpass-0.1.4.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for leanpass-0.1.4.tar.gz
Algorithm Hash digest
SHA256 67c049bc03056ec1a7cc889d6a2a67b4a982efcdf5e225dd05e3e436894e5697
MD5 8e110cc3a25b27e193d46086793d971d
BLAKE2b-256 4d2128a889f1b8d38bf67a6cfb58745ef6c7192b8d373aa63696d764b150619e

See more details on using hashes here.

File details

Details for the file leanpass-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: leanpass-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for leanpass-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 73d334e2d2842360e4389f31b7800c578b9a5676bc571bb22330bbd45f36aebc
MD5 a7ba5b738e4961c46b4e41724e1b0b07
BLAKE2b-256 7cd0e5748d27e4154576cdac2b4e04c90df9291389d2739fcb7d03134d1d7f73

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