pytorch torch.nn.TransformerEncoder

tech2024-03-16  66

API

CLASS torch.nn.TransformerEncoder(encoder_layer, num_layers, norm=None)

TransformerEncoder is a stack of N encoder layers

参数描述encoder_layeran instance of the TransformerEncoderLayer() class (required).num_layersthe number of sub-encoder-layers in the encoder (required).normthe layer normalization component (optional). encoder_layer = nn.TransformerEncoderLayer(d_model=512, nhead=8) transformer_encoder = nn.TransformerEncoder(encoder_layer, num_layers=6) src = torch.rand(10, 32, 512) out = transformer_encoder(src)

参考: https://pytorch.org/docs/master/generated/torch.nn.TransformerEncoder.html#torch.nn.TransformerEncoder

最新回复(0)