class_docstr: Multi-Head Attention module
class_docstr_tok: ["Multi-Head","Attention","module"]
code: def __init__(self, n_head, d_model, d_k, d_v, dropout=0.1):
      super(MultiHeadAttention, self).__init__()
      self.n_head = n_head
      self.d_k = d_k
      self.d_v = d_v
      self.w_qs = nn.Linear(
          d_model,
          n_head * d_k,
          weight_attr=ParamAttr(
              initializer=Normal(
                  mean=0, std=np.sqrt(2.0 / (d_model + d_k))
              )
          ),
      )
      self.w_ks = nn.Linear(
          d_model,
          n_head * d_k,
          weight_attr=ParamAttr(
              initializer=Normal(
                  mean=0, std=np.sqrt(2.0 / (d_model + d_k))
              )
          ),
      )
      self.w_vs = nn.Linear(
          d_model,
          n_head * d_v,
          weight_attr=ParamAttr(
              initializer=Normal(
                  mean=0, std=np.sqrt(2.0 / (d_model + d_v))
              )
          ),
      )
  
      self.attention = ScaledDotProductAttention(
          temperature=np.power(d_k, 0.5)
      )
      self.layer_norm = nn.LayerNorm(d_model)
      self.fc = nn.Linear(
          n_head * d_v,
          d_model,
          weight_attr=ParamAttr(initializer=XavierNormal()),
      )
      self.dropout = nn.Dropout(dropout)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import paddle
  from paddle import ParamAttr
  import paddle.nn
  import paddle.nn.functional
  from paddle.nn.initializer import Normal, XavierNormal
  import numpy
label_desc: Use image node_id 1 to create a new MultiHeadAttention object from inherited base classes: nn with example: obj = MultiHeadAttention(n_head, d_model, d_k, d_v, dropout)