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.0.tar.gz (27.8 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.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: paxjaxlib-0.2.0.tar.gz
  • Upload date:
  • Size: 27.8 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.0.tar.gz
Algorithm Hash digest
SHA256 1290a615ca208701ce04d4cac00c1ead4389099b61b7b05daa0092401679c466
MD5 5b18373eaf77a765ab4fcbf03b2f5f38
BLAKE2b-256 44d5196cfe3765ee2b1b32359c0409bfcca6d17a253bd8cd2b4e69a498ee1165

See more details on using hashes here.

File details

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

File metadata

  • Download URL: paxjaxlib-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 25.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 426dc941eee6a94da9c4f4fb5f54ce0ab78869a810edfea0de8a3dd4e844d5a8
MD5 64b74502af89fbb8526edfdc34bb1307
BLAKE2b-256 113743201007560be7ba097cf6786e6312197d7622f7f27ae9df11dfbbc17e97

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