Leaky Rectified Linear Unit activation function.
Applies element-wise:
Unlike standard ReLU, neurons with negative pre-activations receive a small gradient during back-propagation, avoiding the "dying ReLU" phenomenon where units become permanently inactive.
Parameters
negative_slopefloat= 0.01Slope applied to negative inputs. Default:
0.01.inplacebool= FalseIf
True, modifies the input tensor in-place. Default: False.Notes
- Input: — any shape.
- Output: — same shape as input.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.LeakyReLU(negative_slope=0.1)
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
>>> m(x)
tensor([-0.2, -0.1, 0. , 1. , 2. ])
>>> # Default slope 0.01 — very small leak
>>> m = nn.LeakyReLU()
>>> x = lucid.randn(3, 32)
>>> out = m(x)
>>> out.shape
(3, 32)