liveBook · Manning

ReLU

As explained in Deep Learning with R, Third Edition

A rectified linear unit is the activation function that maps an input x to max(x, 0).

ReLU, or rectified linear unit, maps each input x to max(x, 0): positive values pass through, while negative values become zero. Applied after an affine transformation in a Dense layer, it gives neural networks nonlinear representational power. section 2.3 section 2.3.5

ReLU inside a Dense layer

A Dense layer computes an affine transformation and then applies ReLU: output = relu(dot(input, W) + b). In a sentiment classifier, two intermediate Dense layers use 16 units and ReLU before a final sigmoid output. section 4.1.3

Use ReLU with these practical ideas in mind:

  • Treat it as an element-wise operation: apply max(value, 0) independently to every tensor entry. section 2.3.1
  • Prefer optimized array operations such as pmax over nested loops; vectorized implementations are substantially faster. section 2.3.1
  • Remember why it matters: stacking affine layers without activations remains equivalent to a single affine transformation. section 2.3.5
Listing 4.4 Model definition
model <- keras_model_sequential() |>
  layer_dense(16, activation = "relu") |>
  layer_dense(16, activation = "relu") |>
  layer_dense(1, activation = "sigmoid")

Inspect a complete Keras model definition showing ReLU in intermediate Dense layers and sigmoid in the output layer. section 4.1.3

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines ReLU, explains its tensor and geometric roles, and demonstrates implementation, while deferring deeper treatment of nonlinear transformations.
Examples
Demonstrates ReLU with R array code, optimized pmax operations, geometric figures, and a Keras sentiment-classification model.
What it assumes
Assumes basic matrices, vectors, and tensors, while explaining ReLU and its element-wise behavior from the ground up.
What you can do after
Apply it via Keras or tensor operations to introduce nonlinear behavior in neural-network layers.
How it connects
Connects ReLU to Dense layers, affine transformations, tensor operations, activation functions, sigmoid activation, and binary classification.

Also explained in

Compare how 12 books explain ReLU →

Related concepts

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