class_docstr: Transformer encoder layer.
  
  The layer is composed of the sublayers:
      1. Self-attention layer
      2. Feed-forward network (which is 2 fully-connected layers)
  
  Arguments:
      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.
      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: 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.
class_docstr_tok: ["Transformer","encoder","layer",".","The","layer","is","composed","of","the","sublayers",":","1",".","Self-attention","layer","2",".","Feed-forward","network","(","which","is","2","fully-connected","layers",")","Arguments",":","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",".","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",":","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","."]
code: def __init__(
      self,
      units: int,
      num_heads: int,
      filter_units: int,
      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,
  ) -> None:
      super().__init__()
  
      self._layer_norm = tf.keras.layers.LayerNormalization(
          epsilon=1e-6
      )
      self._mha = MultiHeadAttention(
          units,
          num_heads,
          attention_dropout_rate,
          density,
          unidirectional,
          use_key_relative_position,
          use_value_relative_position,
          max_relative_position,
          heads_share_relative_embedding,
      )
      self._dropout = tf.keras.layers.Dropout(dropout_rate)
  
      self._ffn_layers = [
          tf.keras.layers.LayerNormalization(epsilon=1e-6),
          RandomlyConnectedDense(
              units=filter_units, activation=tf.nn.gelu, density=density
          ),  # (batch_size, length, filter_units)
          tf.keras.layers.Dropout(dropout_rate),
          RandomlyConnectedDense(
              units=units, density=density
          ),  # (batch_size, length, units)
          tf.keras.layers.Dropout(dropout_rate),
      ]
  
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 TransformerEncoderLayer object from inherited base classes: tf.keras.layers with example: obj = 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)