Softmax Classification Example - Jax Typing CST Test
Loading…
Softmax Classification Example — Jax Code
Performing multi-class classification using softmax in JAX.
import jax.numpy as jnp
from jax import grad
# Data
X = jnp.array([[1,2],[3,4],[5,6]])
y = jnp.array([0,1,2])
# Parameters
W = jnp.zeros((3,2))
b = jnp.zeros(3)
# Softmax
def softmax(z):
e_z = jnp.exp(z - jnp.max(z))
return e_z / e_z.sum(axis=0)
# Loss
def loss(W, b):
logits = jnp.dot(X, W.T) + b
y_pred = jnp.array([softmax(l) for l in logits])
return -jnp.mean(jnp.log(y_pred[jnp.arange(len(y)), y]))
grad_loss = grad(loss, argnums=(0,1))Jax Language Guide
JAX is an open-source Python library for high-performance numerical computing, combining NumPy-like API with automatic differentiation (autograd), GPU/TPU acceleration, and composable function transformations for machine learning and scientific computing.
Primary Use Cases
- ▸High-performance machine learning and deep learning model development
- ▸Gradient-based optimization and automatic differentiation
- ▸Physics simulations and scientific computing requiring differentiable functions
- ▸Research in reinforcement learning and generative models
- ▸GPU/TPU accelerated numerical computing at scale
Notable Features
- ▸NumPy-compatible API with hardware acceleration
- ▸Automatic differentiation with `grad`
- ▸Just-in-time compilation (`jit`) for optimized performance
- ▸Vectorization (`vmap`) and parallelization (`pmap`) of functions
- ▸Composable transformations for advanced research pipelines
Origin & Creator
JAX was developed by researchers at Google Research starting in 2018, building on Autograd and XLA (Accelerated Linear Algebra) to enable high-performance, differentiable programming.
Industrial Note
JAX is widely used in cutting-edge machine learning research, physics simulations, reinforcement learning, and differentiable programming, where composable gradients and hardware acceleration are essential.