class_docstr: Transformer encoder.
  
  Encoder stack is made up of `num_layers` identical encoder layers.
  
  Arguments:
      num_layers: Positive integer, number of encoder layers.
      units: Positive integer, output dim of hidden layer.
      num_heads: Positive integer, number of heads
          to repeat the same attention structure.
      filter_units: Positive integer, output dim of the first ffn hidden layer.
      reg_lambda: Float, regularization factor.
      dropout_rate: Float between 0 and 1; fraction of the input units to drop.
      attention_dropout_rate: Float, dropout rate inside attention for training.
      density: Approximate fraction of trainable weights (in
          `RandomlyConnectedDense` layers).
      unidirectional: Boolean, use a unidirectional or bidirectional encoder.
      use_key_relative_position: Boolean, if 'True' use key
          relative embeddings in attention.
      use_value_relative_position: Boolean, if 'True' use value
          relative embeddings in attention.
      max_relative_position: Positive integer, max position for relative embeddings.
      heads_share_relative_embedding: Boolean, if 'True'
          heads will share relative embeddings.
      name: Optional name of the layer.
class_docstr_tok: ["Transformer","encoder",".","Encoder","stack","is","made","up","of","`","num_layers","`","identical","encoder","layers",".","Arguments",":","num_layers",":","Positive","integer",",","number","of","encoder","layers",".","units",":","Positive","integer",",","output","dim","of","hidden","layer",".","num_heads",":","Positive","integer",",","number","of","heads","to","repeat","the","same","attention","structure",".","filter_units",":","Positive","integer",",","output","dim","of","the","first","ffn","hidden","layer",".","reg_lambda",":","Float",",","regularization","factor",".","dropout_rate",":","Float","between","0","and","1",";","fraction","of","the","input","units","to","drop",".","attention_dropout_rate",":","Float",",","dropout","rate","inside","attention","for","training",".","density",":","Approximate","fraction","of","trainable","weights","(","in","`","RandomlyConnectedDense","`","layers",")",".","unidirectional",":","Boolean",",","use","a","unidirectional","or","bidirectional","encoder",".","use_key_relative_position",":","Boolean",",","if","'True","'","use","key","relative","embeddings","in","attention",".","use_value_relative_position",":","Boolean",",","if","'True","'","use","value","relative","embeddings","in","attention",".","max_relative_position",":","Positive","integer",",","max","position","for","relative","embeddings",".","heads_share_relative_embedding",":","Boolean",",","if","'True'","heads","will","share","relative","embeddings",".","name",":","Optional","name","of","the","layer","."]
code: def __init__(
      self,
      num_layers: int,
      units: int,
      num_heads: int,
      filter_units: int,
      reg_lambda: float,
      dropout_rate: float = 0.1,
      attention_dropout_rate: float = 0.0,
      density: float = 0.2,
      unidirectional: bool = False,
      use_key_relative_position: bool = False,
      use_value_relative_position: bool = False,
      max_relative_position: int = 5,
      heads_share_relative_embedding: bool = False,
      name: Optional[Text] = None,
  ) -> None:
      super().__init__(name=name)
  
      self.units = units
      self.unidirectional = unidirectional
  
      l2_regularizer = tf.keras.regularizers.l2(reg_lambda)
      self._embedding = RandomlyConnectedDense(
          units=units,
          kernel_regularizer=l2_regularizer,
          density=density,
      )
      # positional encoding helpers
      self._angles = self._get_angles()
      self._even_indices = np.arange(0, self.units, 2, dtype=np.int32)[
          :, np.newaxis
      ]
      self._odd_indices = np.arange(1, self.units, 2, dtype=np.int32)[
          :, np.newaxis
      ]
  
      self._dropout = tf.keras.layers.Dropout(dropout_rate)
  
      self._enc_layers = [
          TransformerEncoderLayer(
              units,
              num_heads,
              filter_units,
              dropout_rate,
              attention_dropout_rate,
              density,
              unidirectional,
              use_key_relative_position,
              use_value_relative_position,
              max_relative_position,
              heads_share_relative_embedding,
          )
          for _ in range(num_layers)
      ]
      self._layer_norm = tf.keras.layers.LayerNormalization(
          epsilon=1e-6
      )
  
imports: from typing import Optional, Text, Tuple, Union
  import numpy
  import tensorflow
  from keras.utils.control_flow_util import smart_cond
  from tensorflow.keras import backend
  import rasa.shared.utils.cli
  from rasa.utils.tensorflow.layers import RandomlyConnectedDense
label_desc: Use image node_id 1 to create a new TransformerEncoder object from inherited base classes: tf.keras.layers with example: obj = TransformerEncoder(num_layers, units, num_heads, filter_units, reg_lambda, dropout_rate, attention_dropout_rate, density, unidirectional, use_key_relative_position, use_value_relative_position, max_relative_position, heads_share_relative_embedding, name)