class_docstr: Multi-headed attention layer.
  
  Arguments:
      units: Positive integer, output dim of hidden layer.
      num_heads: Positive integer, number of heads
          to repeat the same attention structure.
      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.
class_docstr_tok: ["Multi-headed","attention","layer",".","Arguments",":","units",":","Positive","integer",",","output","dim","of","hidden","layer",".","num_heads",":","Positive","integer",",","number","of","heads","to","repeat","the","same","attention","structure",".","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","."]
code: def _pad_relative_embeddings(
      self, x: tf.Tensor, length: tf.Tensor
  ) -> tf.Tensor:
      # pad the left side to length
      pad_left = x[:, :, :, :1, :]
      pad_left = tf.tile(
          pad_left, (1, 1, 1, length - self.relative_length, 1)
      )
  
      # pad the right side to length
      if self.unidirectional:
          right_relative_length = 1  # current time
          pad_right = tf.zeros_like(x[:, :, :, -1:, :])
      else:
          right_relative_length = self.relative_length
          pad_right = x[:, :, :, -1:, :]
      pad_right = tf.tile(
          pad_right, (1, 1, 1, length - right_relative_length, 1)
      )
  
      return tf.concat([pad_left, x, pad_right], axis=-2)
  
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 3 for calling the MultiHeadAttention obj's underlying member method code with example usage: obj._pad_relative_embeddings(x, length) and returns: tf