espnet2.gan_codec.shared.encoder.snake_activation.snake
espnet2.gan_codec.shared.encoder.snake_activation.snake
espnet2.gan_codec.shared.encoder.snake_activation.snake()
Applies the Snake activation function to the input tensor.
The Snake activation function is a non-linear transformation that enhances the representation power of neural networks by introducing a sine-based component, controlled by the parameter alpha. This activation is designed to be used in deep learning models, particularly within neural network layers.
- Parameters:
- x (torch.Tensor) – Input tensor of shape (N, C, L), where N is the batch size, C is the number of channels, and L is the length of each channel.
- alpha (torch.Tensor) – Parameter controlling the sine transformation, should be of shape (1, 1, 1) or broadcastable to the shape of x.
- Returns: Output tensor after applying the Snake activation function, : with the same shape as the input tensor x.
- Return type: torch.Tensor
Examples
>>> x = torch.randn(2, 3, 4) # Batch of 2, 3 channels, length 4
>>> alpha = torch.tensor([[[0.5]]]) # Alpha value for the transformation
>>> output = snake(x, alpha)
>>> print(output.shape)
torch.Size([2, 3, 4])
espnet2.gan_codec.shared.encoder.snake_activation.alpha
The alpha parameter for the Snake activation, initialized to a tensor of ones with shape (1, 1, 1).
Type: torch.Tensor
Raises:ValueError – If the input tensor x is not of shape (N, C, L).
NOTE
This activation function is designed to be used within neural networks to improve learning capacity and can be integrated into custom layers.