class
LeakyReLU
extends
ModuleLeakyReLU(negative_slope: float = 0.01, inplace: bool = False)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)Methods (3)
dunder
__init__
→None__init__(negative_slope: float = 0.01, inplace: bool = False)Initialise the LeakyReLU module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Apply the activation function element-wise.
Parameters
inputTensorInput tensor of arbitrary shape.
Returns
TensorOutput tensor of the same shape as input.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.