docstr: Parameters
  ----------
  num_layers :
      The number of layers
  recurrent : bool
      Whether the layers share weights or not
  units
  hidden_size
  num_heads
  dropout
  layer_norm_eps
  data_norm
      Whether to apply LayerNorm to the data
  pre_norm
      Whether to apply LayerNorm before the attention layer.
  weight_initializer
  bias_initializer
  activation
  dtype
  layout
docstr_tok: ["Parameters","--","--","--","--","--","num_layers",":","The","number","of","layers","recurrent",":","bool","Whether","the","layers","share","weights","or","not","units","hidden_size","num_heads","dropout","layer_norm_eps","data_norm","Whether","to","apply","LayerNorm","to","the","data","pre_norm","Whether","to","apply","LayerNorm","before","the","attention","layer",".","weight_initializer","bias_initializer","activation","dtype","layout"]
code: def __init__(
      self,
      num_layers=6,
      recurrent=False,
      units=512,
      hidden_size=2048,
      num_heads=8,
      activation_dropout=0.0,
      dropout=0.1,
      use_qkv_bias=True,
      attention_dropout=0.1,
      layer_norm_eps=1e-5,
      data_norm=False,
      pre_norm=False,
      weight_initializer=None,
      bias_initializer="zeros",
      activation="relu",
      dtype="float32",
      layout="NT",
  ):
      """
  
      Parameters
      ----------
      num_layers :
          The number of layers
      recurrent : bool
          Whether the layers share weights or not
      units
      hidden_size
      num_heads
      dropout
      layer_norm_eps
      data_norm
          Whether to apply LayerNorm to the data
      pre_norm
          Whether to apply LayerNorm before the attention layer.
      weight_initializer
      bias_initializer
      activation
      dtype
      layout
      """
      super().__init__()
      self._dtype = dtype
      self.num_layers = num_layers
      self._recurrent = recurrent
      self._data_norm = data_norm
      self._pre_norm = pre_norm
      self._layout = layout
      assert layout in ["TN", "NT"], (
          "Invalid layout received = {}. "
          'Only "TN" and "NT" are accepted!'.format(layout)
      )
      self.dropout_layer = nn.Dropout(dropout)
      if self._pre_norm:
          self.ln_final = nn.LayerNorm(
              epsilon=layer_norm_eps, in_channels=units
          )
      if self._data_norm:
          self.ln_data = nn.LayerNorm(
              epsilon=layer_norm_eps, in_channels=units
          )
      # Construct the intermediate layers
      self.layers = nn.HybridSequential()
      real_num_layers = 1 if recurrent else num_layers
      for i in range(real_num_layers):
          self.layers.add(
              TransformerEncoderLayer(
                  units=units,
                  hidden_size=hidden_size,
                  num_heads=num_heads,
                  hidden_dropout_prob=dropout,
                  attention_dropout_prob=attention_dropout,
                  activation_dropout_prob=activation_dropout,
                  use_qkv_bias=use_qkv_bias,
                  layer_norm_eps=layer_norm_eps,
                  weight_initializer=weight_initializer,
                  bias_initializer=bias_initializer,
                  pre_norm=pre_norm,
                  activation=activation,
                  layout=self._layout,
                  dtype=dtype,
              )
          )
  
imports: import numpy
  import mxnet
  from mxnet import np, npx
  from mxnet import use_np
  from mxnet.gluon import nn, HybridBlock
  from typing import Optional, Tuple, List
  from ..utils.registry import Registry
  from ..attention_cell import MultiHeadAttentionCell, gen_self_attn_mask, gen_mem_attn_mask
  from ..layers import PositionalEmbedding, PositionwiseFFN, InitializerType
  from ..utils.config import CfgNode
  from ..sequence_sampler import BaseStepDecoder
label_desc: Use image node_id 1 to create a new TransformerEncoder object from inherited base classes: HybridBlock with example: obj = TransformerEncoder(num_layers, recurrent, units, hidden_size, num_heads, activation_dropout, dropout, use_qkv_bias, attention_dropout, layer_norm_eps, data_norm, pre_norm, weight_initializer, bias_initializer, activation, dtype, layout)