ding.torch_utils.network.activation¶
ding.torch_utils.network.activation
¶
Lambda
¶
Bases: Module
Overview
A custom lambda module for constructing custom layers.
Interfaces:
__init__, forward.
GLU
¶
Bases: Module
Overview
Gating Linear Unit (GLU), a specific type of activation function, which is first proposed in Language Modeling with Gated Convolutional Networks.
Interfaces:
__init__, forward.
__init__(input_dim, output_dim, context_dim, input_type='fc')
¶
Overview
Initialize the GLU module.
Arguments:
- input_dim (:obj:int): The dimension of the input tensor.
- output_dim (:obj:int): The dimension of the output tensor.
- context_dim (:obj:int): The dimension of the context tensor.
- input_type (:obj:str): The type of input, now supports ['fc', 'conv2d']
forward(x, context)
¶
Overview
Compute the GLU transformation of the input tensor.
Arguments:
- x (:obj:torch.Tensor): The input tensor.
- context (:obj:torch.Tensor): The context tensor.
Returns:
- x (:obj:torch.Tensor): The output tensor after GLU transformation.
Swish
¶
Bases: Module
Overview
Swish activation function, which is a smooth, non-monotonic activation function. For more details, please refer to Searching for Activation Functions.
Interfaces:
__init__, forward.
GELU
¶
Bases: Module
Overview
Gaussian Error Linear Units (GELU) activation function, which is widely used in NLP models like GPT, BERT. For more details, please refer to the original paper: https://arxiv.org/pdf/1606.08415.pdf.
Interfaces:
__init__, forward.
build_activation(activation, inplace=None)
¶
Overview
Build and return the activation module according to the given type.
Arguments:
- activation (:obj:str): The type of activation module, now supports ['relu', 'glu', 'prelu', 'swish', 'gelu', 'tanh', 'sigmoid', 'softplus', 'elu', 'square', 'identity'].
- inplace (Optional[:obj:bool): Execute the operation in-place in activation, defaults to None.
Returns:
- act_func (:obj:nn.module): The corresponding activation module.
Full Source Code
../ding/torch_utils/network/activation.py