Skip to main content

A simple neural network implementation using JAX

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 GNU GENERAL PUBLIC 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.1.1.tar.gz (26.0 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.1.1-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for paxjaxlib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 280c0303e4cc8e750e5ada9771b79f4911ec53096dee47fa799f4afcae353948
MD5 64b05e1e04763286d02f291740044a55
BLAKE2b-256 c41268ffc2b7885bfff8c9240bffd5665137a0a3aae17b6feb0ec68169d4efec

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for paxjaxlib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2d7e4ed67906f09181ac9305c1801f00c566a2fcb49fb0abb8b06402c53f22d
MD5 604cb1391066311ec25f659f0754926c
BLAKE2b-256 b63bf7610130ae03e4ea5c2854198f55fd59e7b9ea2a2f3111c44951540c22fb

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