fn
leaky_relu
→Tensorleaky_relu(x: Tensor, negative_slope: float = 0.01, inplace: bool = False)Leaky rectified linear unit activation.
A simple modification of relu that lets a small, non-zero gradient
pass through for negative inputs. This avoids the dying ReLU problem
where neurons stuck on the negative side stop updating because their
gradient is exactly zero.
Parameters
xTensorInput tensor of any shape; activation is applied element-wise.
negative_slopefloat= 0.01Slope of the linear branch for negative inputs.
Default
0.01.inplacebool= FalseAccepted for API compatibility; currently ignored.
Returns
TensorActivated tensor with the same shape as x.
Notes
The derivative is for and for
. Unlike relu, the derivative is everywhere
non-zero (assuming ), so gradient signal continues
to flow through inactive units. Use Leaky ReLU when ReLU networks are
showing many permanently dead neurons; for a learnable slope, see
prelu.
Examples
>>> import lucid
>>> from lucid.nn.functional import leaky_relu
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0])
>>> leaky_relu(x, negative_slope=0.1)
Tensor([-0.2000, -0.1000, 0.0000, 1.0000])