liveBook · Manning

Activation function

As explained in Deep Learning with JAX

A nonlinear function applied inside a neural network to let stacked layers represent more than a single linear transformation.

Why do stacked neural-network layers need more than matrix multiplication? An activation function adds nonlinearity, allowing the network to represent relationships that a single linear transformation cannot. section 2.4.2

A feed-forward layer computes y = f(x × w + b): weights multiply the incoming values, biases shift the result, and f applies the activation function. Without f, layered linear combinations collapse into one linear model, limiting classification to linearly separable problems such as excluding XOR. section 2.4 section 2.4.2

Common activation-function choices have different practical histories and properties:

  • Sigmoid and hyperbolic tangent are smooth and differentiable at every point. section 2.4.2
  • ReLU is not smooth at zero, yet practitioners found that networks often learn faster with it. section 2.4.2
  • GELU is among the later designed activation functions. section 2.4.2

Using Swish in a JAX forward pass

from jax.nn import swish def predict(params, image): activations = image for w, b in params[:-1]: outputs = jnp.dot(w, activations) + b activations = swish(outputs) final_w, final_b = params[-1] logits = jnp.dot(final_w, activations) + final_b return logits Here, Swish transforms each hidden-layer result, while the final layer returns logits for the ten output classes. section 2.4.2 section 2.4

Listing 2.5 The forward pass of a neural network
import jax.numpy as jnp
from jax.nn import swish                             #1
  
def predict(params, image):                          #2
  """Function for per-example predictions."""
  activations = image                                #3
  for w, b in params[:-1]:                           #4
    outputs = jnp.dot(w, activations) + b            #5
    activations = swish(outputs)                     #5
  
  final_w, final_b = params[-1]                      #6
  logits = jnp.dot(final_w, activations) + final_b   #6
  return logits

Inspect the complete forward-pass listing showing where the activation function sits between weighted layers. section 2.4.2

How Deep Learning with JAX covers it

How deep it goes
Defines layer computation, explains linear collapse, and demonstrates Swish in JAX without deriving activation formulas.
Examples
Demonstrates Swish inside a JAX prediction function for a ten-class neural network.
What it assumes
Assumes basic neural-network layers, weights, biases, and matrix operations while explaining nonlinearity from first principles.
What you can do after
Apply activation functions through jax.nn.swish in a stateless JAX forward pass.
How it connects
Connects neural networks, forward passes, JAX, Swish, sigmoid, hyperbolic tangent, ReLU, and GELU.

Also explained in

Compare how 14 books explain activation function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with JAX. The section links point to the parts of the book it draws on.