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","."]
docstr: Apply transformer encoder layer.
  
  Arguments:
      x: A tensor with shape [batch_size, length, units].
      pad_mask: Float tensor with shape broadcastable
          to (..., length, length). Defaults to None.
      training: A bool, whether in training mode or not.
  
  Returns:
      Transformer encoder layer output with shape [batch_size, length, units]
docstr_tok: ["Apply","transformer","encoder","layer",".","Arguments",":","x",":","A","tensor","with","shape","[","batch_size",",","length",",","units","]",".","pad_mask",":","Float","tensor","with","shape","broadcastable","to","(","...",",","length",",","length",")",".","Defaults","to","None",".","training",":","A","bool",",","whether","in","training","mode","or","not",".","Returns",":","Transformer","encoder","layer","output","with","shape","[","batch_size",",","length",",","units","]"]
code: def call(
      self,
      x: tf.Tensor,
      pad_mask: Optional[tf.Tensor] = None,
      training: Optional[Union[tf.Tensor, bool]] = None,
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Apply transformer encoder layer.
  
      Arguments:
          x: A tensor with shape [batch_size, length, units].
          pad_mask: Float tensor with shape broadcastable
              to (..., length, length). Defaults to None.
          training: A bool, whether in training mode or not.
  
      Returns:
          Transformer encoder layer output with shape [batch_size, length, units]
      """
      if training is None:
          training = K.learning_phase()
  
      x_norm = self._layer_norm(x)  # (batch_size, length, units)
      attn_out, attn_weights = self._mha(
          x_norm, x_norm, pad_mask=pad_mask, training=training
      )
      attn_out = self._dropout(attn_out, training=training)
      x += attn_out
  
      ffn_out = x  # (batch_size, length, units)
      for layer in self._ffn_layers:
          ffn_out = layer(ffn_out, training=training)
      x += ffn_out
  
      # (batch_size, length, units), (batch_size, num_heads, length, length)
      return x, attn_weights
  
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 2 for calling the TransformerEncoderLayer obj's underlying member method code with example usage: obj.call(x, pad_mask, training) and returns: x,  attn_weights