liveBook · Manning

ReLU

As explained in Inside Deep Learning: Math, Algorithms, Models

A rectified linear unit activation function that outputs zero for negative inputs and the input itself for nonnegative inputs.

ReLU is a simple nonlinear activation that helps feed-forward and convolutional networks converge to more accurate solutions in fewer epochs than saturating activations such as tanh or sigmoid. section 6.1.2 section 6.0

For an input x, ReLU(x) = max(0, x): positive inputs pass through unchanged, while negative inputs become zero. Its derivative is 1 for positive inputs and 0 for nonpositive inputs. section 6.1.2

Use ReLU with these tradeoffs in mind:

  • Prefer it when saturated tanh or sigmoid activations cause vanishing-gradient concerns; its positive region keeps a constant derivative. section 6.1.2
  • Watch for inactive neurons: inputs at or below zero receive no gradient, which can be damaging in very small networks. section 6.1.2
  • Consider LeakyReLU when a nonzero negative-side gradient is useful; it replaces the hard zero with a small slope. section 6.1.2 section 6.1.3

Compare the activation shapes

Generate inputs from -5 to 5 and compute `relu_activation = np.maximum(0, activation_input)`. Plot it alongside tanh, sigmoid, and LeakyReLU to see ReLU’s zero-valued negative region and linear positive region. section 6.1.2

activation_input = np.linspace(-5, 5, num=200) relu_activation =
    np.maximum(0,activation_input) leaky_relu_activation =
    np.maximum(0.3*activation_input,activation_input)

    sns.lineplot(x=activation_input, y=tanh_activation, color=’red’, 
     label="tanh(x)") 
    sns.lineplot(x=activation_input, y=sigmoid_activation, color=’blue’, 
     label="σ(x)") 
    sns.lineplot(x=activation_input, y=relu_activation, color=’green’, 
     label="ReLU(x)") 
    sns.lineplot(x=activation_input, y=leaky_relu_activation, color=’purple’, 
     label="LeakyReLU(x)")

[15]: <AxesSubplot:>

Inspect the supplied activation-function comparison, including ReLU and LeakyReLU values across negative and positive inputs. section 6.1.2

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Explains the piecewise function, derivative, gradient behavior, plots, and LeakyReLU tradeoff, but defers broader architecture design.
Examples
Uses NumPy activation values, comparison plots, and Fashion-MNIST fully connected and CNN training experiments.
What it assumes
Assumes familiarity with activation functions and neural networks while defining ReLU and its derivative from first principles.
What you can do after
Apply ReLU by replacing saturating hidden-layer activations and diagnose inactive-neuron risks through derivative and training behavior.
How it connects
Connects ReLU to activation functions, vanishing gradients, tanh, sigmoid, LeakyReLU, feed-forward networks, and convolutional neural networks.

Also explained in

Compare how 12 books explain ReLU →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.