espnet.nets.pytorch_backend.conformer.contextual_block_encoder_layer.ContextualBlockEncoderLayer
About 1 min
espnet.nets.pytorch_backend.conformer.contextual_block_encoder_layer.ContextualBlockEncoderLayer
class espnet.nets.pytorch_backend.conformer.contextual_block_encoder_layer.ContextualBlockEncoderLayer(size, self_attn, feed_forward, feed_forward_macaron, conv_module, dropout_rate, total_layer_num, normalize_before=True, concat_after=False)
Bases: Module
Contexutal Block Encoder layer module.
- Parameters:
- size (int) – Input dimension.
- self_attn (torch.nn.Module) – Self-attention module instance. MultiHeadedAttention or RelPositionMultiHeadedAttention instance can be used as the argument.
- feed_forward (torch.nn.Module) – Feed-forward module instance. PositionwiseFeedForward, MultiLayeredConv1d, or Conv1dLinear instance can be used as the argument.
- feed_forward_macaron (torch.nn.Module) – Additional feed-forward module instance. PositionwiseFeedForward, MultiLayeredConv1d, or Conv1dLinear instance can be used as the argument.
- conv_module (torch.nn.Module) – Convolution module instance. ConvlutionModule instance can be used as the argument.
- dropout_rate (float) – Dropout rate.
- total_layer_num (int) – Total number of layers
- normalize_before (bool) – Whether to use layer_norm before the first block.
- concat_after (bool) – Whether to concat attention layer’s input and output. if True, additional linear will be applied. i.e. x -> x + linear(concat(x, att(x))) if False, no additional linear will be applied. i.e. x -> x + att(x)
Construct an EncoderLayer object.
forward(x, mask, infer_mode=False, past_ctx=None, next_ctx=None, is_short_segment=False, layer_idx=0, cache=None)
Calculate forward propagation.
forward_infer(x, mask, past_ctx=None, next_ctx=None, is_short_segment=False, layer_idx=0, cache=None)
Compute encoded features.
- Parameters:
- x_input (torch.Tensor) – Input tensor (#batch, time, size).
- mask (torch.Tensor) – Mask tensor for the input (#batch, 1, time).
- past_ctx (torch.Tensor) – Previous contexutal vector
- next_ctx (torch.Tensor) – Next contexutal vector
- cache (torch.Tensor) – Cache tensor of the input (#batch, time - 1, size).
- Returns: Output tensor (#batch, time, size). torch.Tensor: Mask tensor (#batch, 1, time). cur_ctx (torch.Tensor): Current contexutal vector next_ctx (torch.Tensor): Next contexutal vector layer_idx (int): layer index number
- Return type: torch.Tensor
forward_train(x, mask, past_ctx=None, next_ctx=None, layer_idx=0, cache=None)
Compute encoded features.
- Parameters:
- x_input (torch.Tensor) – Input tensor (#batch, time, size).
- mask (torch.Tensor) – Mask tensor for the input (#batch, time).
- past_ctx (torch.Tensor) – Previous contexutal vector
- next_ctx (torch.Tensor) – Next contexutal vector
- cache (torch.Tensor) – Cache tensor of the input (#batch, time - 1, size).
- Returns: Output tensor (#batch, time, size). torch.Tensor: Mask tensor (#batch, time). cur_ctx (torch.Tensor): Current contexutal vector next_ctx (torch.Tensor): Next contexutal vector layer_idx (int): layer index number
- Return type: torch.Tensor