modelzoo.common.pytorch.layers.TransformerEncoder#

import path: modelzoo.common.pytorch.layers.TransformerEncoder

TransformerEncoder (encoder_layer, num_layers, norm=None, enable_nested_tensor=False):

  • encoder_layer: an instance of the TransformerEncoderLayer() class (required).

  • num_layers: the number of sub-encoder-layers in the encoder (required).

  • norm: the layer normalization component (optional).

forward (src, mask=None, src_key_padding_mask=None):

  • src (Tensor): the sequence to the encoder (required). shape [batch_size, src_seq_length, embed_dim].

  • mask (Tensor): the mask for the src sequence (optional). shape [src_seq_length, src_seq_length].

  • src_key_padding_mask (Tensor): the mask for the src keys per batch (optional). shape [batch_size, src_seq_length].