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.1.2.tar.gz (14.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.1.2-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for paxjaxlib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d7c1e3066e2eef838942cf9a8fa2d53d3d1ad75c058c77e3251918a6b9e57e26
MD5 2dc5d4e96c1e272d4e9bf20b6533ffe4
BLAKE2b-256 5cf4f4b4e8731578e4d88d98025ed1a6e381fdcd088055fcc949c92b1c623a1d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for paxjaxlib-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cad956de214028e37c94a30328f89a6cc55752bdb446572f7fdf810938b4a553
MD5 711044b813ef5297f1118ec24fe0f081
BLAKE2b-256 0dbec13fe20e886baa9c80b422fa27f2b935422910b9880bf318050a7bcd900a

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