Skip to main content

A simple neural network implementation using JAX, made for educational purposes

Project description

paxjaxlib

A simple and functional neural network library built on JAX.

CI PyPI version


paxjaxlib is a lightweight and modular deep learning library that embraces JAX's functional programming paradigm. Just a simple, yet powerful, API for building and training neural networks.

Installation

You can install paxjaxlib directly from PyPI:

pip install paxjaxlib

Or, for development, clone the repository and install in editable mode:

git clone https://github.com/paxamans/paxjaxlib.git
cd paxjaxlib
pip install -e .[dev]

Quick Start

Here's a quick example of how to define, train, and evaluate a simple NeuralNetwork on dummy data.

import jax
import jax.numpy as jnp
import optax
from paxjaxlib.layers import Dense
from paxjaxlib.models import NeuralNetwork
from paxjaxlib.training import Trainer

# 1. Generate dummy data
key = jax.random.PRNGKey(0)
X = jax.random.normal(key, (100, 10))
y = jax.random.normal(key, (100, 1))

# 2. Define the model
# The model is a pytree, so its parameters can be manipulated functionally.
model = NeuralNetwork([
    Dense(10, 64),
    jax.nn.relu,
    Dense(64, 1)
])

# 3. Initialize the trainer with an Optax optimizer
# The trainer manages the training loop and state.
trainer = Trainer(model, optimizer=optax.adam(1e-3))

# 4. Train the model
# The `train` method returns a history of metrics.
history = trainer.train(X, y, epochs=10, batch_size=32)
print("Training loss:", history['loss'][-1])

# 5. Make predictions
# The trained model is available at `trainer.model`.
predictions = trainer.model(X)

Architecture

The core of paxjaxlib is the paxjaxlib.core.Module, which serves as the base for all layers and models. By inheriting from Module, classes are automatically registered as JAX pytrees.

  • Models are data: A NeuralNetwork or Dense layer is a simple data structure. All parameters are stored as attributes.
  • Stateless updates: Training updates produce a new, updated model object instead of modifying an existing one in place.
  • Gradients with respect to models: You can compute gradients directly with respect to the entire model object, for example: grads = jax.grad(loss_fn)(model, X, y).

Wiki & Documentation

Coming soon

License

This project is licensed under the MIT LICENSE.

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

paxjaxlib-0.2.1.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

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

paxjaxlib-0.2.1-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for paxjaxlib-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6250f0c9ddf6a6be256391cbb243871fdf51c5c3f182cd0f4073a1398ca07f23
MD5 bacc0d808e7c6abeaec0cb41145e5aa8
BLAKE2b-256 63c98840acd49743c629e763f3a831c8efe0fecfe4f4f7c9d2060fe55018c8e7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for paxjaxlib-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e6c95a05993a62ac581d54f1531c5495fc0158b1b3ea2d5bef6d55bee6bc751
MD5 146d988bda1961faef76a3dfff514df3
BLAKE2b-256 31e3919f7e969e37db5c94357f349f4a680a33312857a3488bb3a384a5e4168f

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