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","."]
docstr: Create relative embeddings.
docstr_tok: ["Create","relative","embeddings","."]
code: def _create_relative_embeddings(self) -> None:
      """Create relative embeddings."""
      relative_embedding_shape: Optional[
          Union[Tuple[int, int], Tuple[int, int, int]]
      ] = None
      self.key_relative_embeddings = None
      self.value_relative_embeddings = None
  
      if (
          self.use_key_relative_position
          or self.use_value_relative_position
      ):
          if not self.relative_length:
              raise ValueError(
                  f"Max relative position {self.relative_length} "
                  f"should be > 0 when using relative attention."
              )
  
          if self.unidirectional:
              relative_length = self.relative_length
          else:
              relative_length = 2 * self.relative_length - 1
  
          if self.heads_share_relative_embedding:
              relative_embedding_shape = (relative_length, self._depth)
          else:
              relative_embedding_shape = (
                  self.num_heads,
                  relative_length,
                  self._depth,
              )
  
      if self.use_key_relative_position:
          self.key_relative_embeddings = self.add_weight(
              shape=relative_embedding_shape,
              name="key_relative_embeddings",
          )
  
      if self.use_value_relative_position:
          self.value_relative_embeddings = self.add_weight(
              shape=relative_embedding_shape,
              name="value_relative_embeddings",
          )
  
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 MultiHeadAttention obj's underlying member method code with example usage: obj._create_relative_embeddings() without return types