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.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.2.tar.gz (10.0 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.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for leanpass-0.1.2.tar.gz
Algorithm Hash digest
SHA256 407c8cc5d2c76e83d82916c7d6bef07a23d321539cf853646048d483a34f37e7
MD5 6fea7f04ca93b90f38c24ebf0fa192f8
BLAKE2b-256 9a390b974afcf072c44092be0a9de141e036a6db6cfd7941bfd49ce74e257633

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for leanpass-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 18b287498153e6a31019362ddf0b418ea24d8935114d7f51dfb57c237d4c859e
MD5 d0a51bae1caaf0822585f3974ba85cff
BLAKE2b-256 2a35f39eb30359ed2c79159e12a34f7f8f3abacb23f2641b7459428d81912e42

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