class_docstr: Multi-headed attention from "Attention Is All You Need
class_docstr_tok: ["Multi-headed","attention","from","``","Attention","Is","All","You","Need"]
code: def __init__(
      self,
      embed_dim: int,
      num_heads: int,
      dropout: float = 0.0,
      is_decoder: bool = False,
      bias: bool = True,
      **kwargs,
  ):
      super().__init__(**kwargs)
      self.embed_dim = embed_dim
  
      self.num_heads = num_heads
      self.dropout = tf.keras.layers.Dropout(dropout)
      self.head_dim = embed_dim // num_heads
      if (self.head_dim * num_heads) != self.embed_dim:
          raise ValueError(
              f"embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim}"
              f" and `num_heads`: {num_heads})."
          )
      self.scaling = self.head_dim**-0.5
      self.is_decoder = is_decoder
  
      self.k_proj = tf.keras.layers.Dense(
          embed_dim, use_bias=bias, name="k_proj"
      )
      self.q_proj = tf.keras.layers.Dense(
          embed_dim, use_bias=bias, name="q_proj"
      )
      self.v_proj = tf.keras.layers.Dense(
          embed_dim, use_bias=bias, name="v_proj"
      )
      self.out_proj = tf.keras.layers.Dense(
          embed_dim, use_bias=bias, name="out_proj"
      )
  
imports: from __future__ import annotations
  import math
  import random
  from typing import Any, Optional, Tuple, Union
  import numpy
  import tensorflow
  from ...activations_tf import get_tf_activation
  from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
  from ...modeling_tf_outputs import TFBaseModelOutputWithPastAndCrossAttentions, TFCausalLMOutputWithCrossAttentions
  from ...modeling_tf_utils import TFCausalLanguageModelingLoss, TFModelInputType, TFPreTrainedModel, TFSharedEmbeddings, get_initializer, keras_serializable, unpack_inputs
  from ...tf_utils import check_embeddings_within_bounds, shape_list, stable_softmax
  from ...utils import logging
  from .configuration_xglm import XGLMConfig
label_desc: Use image node_id 1 to create a new TFXGLMAttention object from inherited base classes: tf.keras.layers with example: obj = TFXGLMAttention(embed_dim, num_heads, dropout, is_decoder, bias)