EnhancedLinear#
- class EnhancedLinear(layer, activation=None, dropout=None)[source]
Bases:
Module
A wrapper class for enhancing a linear layer with activation and/or dropout.
- Parameters:
layer (torch.nn.Module) – The linear layer to be enhanced.
activation (torch.nn.Module) – The activation function to be applied after the linear layer.
dropout (float) – The dropout probability to be applied after the activation (if provided).
- Example:
>>> linear_layer = torch.nn.Linear(10, 20) >>> activation = torch.nn.ReLU() >>> dropout_prob = 0.5 >>> enhanced_linear = EnhancedLinear(linear_layer, activation, dropout_prob)
Initializes the EnhancedLinear module.
- Parameters:
layer (torch.nn.Module) – The linear layer to be enhanced.
activation (torch.nn.Module) – The activation function to be applied after the linear layer.
dropout (float) – The dropout probability to be applied after the activation (if provided).
- forward(x)[source]
Forward pass through the enhanced linear module.
- Parameters:
x (torch.Tensor) – Input tensor.
- Returns:
Output tensor after passing through the enhanced linear module.
- Return type: