Skip to main content

The ✨Magical✨ JAX NN Library.

*Serket is the goddess of magic in Egyptian mythology

Tests pyver codestyle Downloads codecov

🛠️ Installation

pip install serket

📖 Description

  • serket aims to be the most intuitive and easy-to-use Neural network library in JAX.
  • serket is built on top of pytreeclass
  • serket currently implements
    • Linear, FNN
    • Dropout
    • Sequential
    • Lambda

⏩ Quick Example

Simple Fully connected neural network.

Model definition

import serket as sk 
import jax.numpy as jnp
import jax.random as jr


@sk.treeclass
class NN:
    def __init__(
        self, 
        in_features:int, 
        out_features:int, 
        hidden_features: int, key:jr.PRNGKey = jr.PRNGKey(0)):

        k1,k2,k3 = jr.split(key, 3)

        self.l1 = sk.nn.Linear(in_features, hidden_features, key=k1)
        self.l2 = sk.nn.Linear(hidden_features, hidden_features, key=k2)
        self.l3 = sk.nn.Linear(hidden_features, out_features, key=k3)
    
    def __call__(self, x):
        x = self.l1(x)
        x = jax.nn.relu(x)
        x = self.l2(x)
        x = jax.nn.relu(x)
        x = self.l3(x)
        return x


model = NN(
    in_features=1, 
    out_features=1, 
    hidden_features=128, 
    key=jr.PRNGKey(0))
# `*` represents untrainable(static) nodes.
print(model.tree_diagram())
NN
    ├── l1=Linear
       ├── weight=f32[1,128]
       ├── bias=f32[128]
       * in_features=1
       * out_features=128
       * weight_init_func=init(key,shape,dtype)
       * bias_init_func=Lambda(key,shape)    
    ├── l2=Linear
       ├── weight=f32[128,128]
       ├── bias=f32[128]
       * in_features=128
       * out_features=128
       * weight_init_func=init(key,shape,dtype)
       * bias_init_func=Lambda(key,shape)    
    └── l3=Linear
        ├── weight=f32[128,1]
        ├── bias=f32[1]
        * in_features=128
        * out_features=1
        * weight_init_func=init(key,shape,dtype)
        * bias_init_func=Lambda(key,shape) 
>>> print(model.summary())
┌────┬──────┬─────────┬───────┬───────────────────┐
NameType  Param #  │Size   │Config             │
├────┼──────┼─────────┼───────┼───────────────────┤
l1  Linear256(0)   1.00KB weight=f32[1,128]  
                   (0.00B)bias=f32[128]      
├────┼──────┼─────────┼───────┼───────────────────┤
l2  Linear16,512(0)64.50KBweight=f32[128,128]
                   (0.00B)bias=f32[128]      
├────┼──────┼─────────┼───────┼───────────────────┤
l3  Linear129(0)   516.00Bweight=f32[128,1]  
                   (0.00B)bias=f32[1]        
└────┴──────┴─────────┴───────┴───────────────────┘
Total count :	16,897(0)
Dynamic count :	16,897(0)
Frozen count :	0(0)
---------------------------------------------------
Total size :	66.00KB(0.00B)
Dynamic size :	66.00KB(0.00B)
Frozen size :	0.00B(0.00B)
===================================================

Train

x = jnp.linspace(0,1,100)[:,None]
y = x**3 + jax.random.uniform(jax.random.PRNGKey(0),(100,1))*0.01

@jax.value_and_grad
def loss_func(model,x,y):
    return jnp.mean((model(x)-y)**2)

@jax.jit
def update(model,x,y):
    value,grad = loss_func(model,x,y)
    return value , model - 1e-3*grad

for _ in range(20_000):
    value,model = update(model,x,y)

Filter

  • Filter by (1)value, (2)field name, (3)field type, (4)field metadata
  • See here for more

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serket-0.0.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

serket-0.0.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file serket-0.0.1.tar.gz.

File metadata

  • Download URL: serket-0.0.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for serket-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9a3c99e99deb2a954b46a4e17fe3adda00bdc5d5ef444786a917e677f79c1948
MD5 feb0e39cf37982702ebecaef337b27be
BLAKE2b-256 d06b76dc0b3e76bdbaa8dde89e4d5932232a4250d44a9844971e896bd3b821d9

See more details on using hashes here.

File details

Details for the file serket-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: serket-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for serket-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9931f3278e2764af4178915f8b9eb256f8991339b286460b9aef0d307b83e4e
MD5 9af208a121b5e8543e68013377d18e55
BLAKE2b-256 5d6661cfba4fb5ac97c397d7a7768035e58cd0968cb5dab61419ad8416fb14d4

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 Sentry Error logging StatusPage Status page