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











