class_docstr: Global attention takes a matrix and a query vector. It
  then computes a parameterized convex combination of the matrix
  based on the input query.
  
  Constructs a unit mapping a query `q` of size `dim`
  and a source matrix `H` of size `n x dim`, to an output
  of size `dim`.
  
  
  .. mermaid::
  
     graph BT
        A[Query]
        subgraph RNN
          C[H 1]
          D[H 2]
          E[H N]
        end
        F[Attn]
        G[Output]
        A --> F
        C --> F
        D --> F
        E --> F
        C -.-> G
        D -.-> G
        E -.-> G
        F --> G
  
  All models compute the output as
  :math:`c = \sum_{j=1}^{\text{SeqLength}} a_j H_j` where
  :math:`a_j` is the softmax of a score function.
  Then then apply a projection layer to [q, c].
  
  However they
  differ on how they compute the attention score.
  
  * Luong Attention (dot, general):
     * dot: :math:`\text{score}(H_j,q) = H_j^T q`
     * general: :math:`\text{score}(H_j, q) = H_j^T W_a q`
  
  
  * Bahdanau Attention (mlp):
     * :math:`\text{score}(H_j, q) = v_a^T \text{tanh}(W_a q + U_a h_j)`
  
  
  Args:
     dim (int): dimensionality of query and key
     coverage (bool): use coverage term
     attn_type (str): type of attention to use, options [dot,general,mlp]
     attn_func (str): attention function to use, options [softmax,sparsemax]
docstr: Args:
    h_t (FloatTensor): sequence of queries ``(batch, tgt_len, dim)``
    h_s (FloatTensor): sequence of sources ``(batch, src_len, dim``
  
  Returns:
    FloatTensor: raw attention scores (unnormalized) for each src index
      ``(batch, tgt_len, src_len)``
docstr_tok: ["Args",":","h_t","(","FloatTensor",")",":","sequence","of","queries","``","(","batch",",","tgt_len",",","dim",")","``","h_s","(","FloatTensor",")",":","sequence","of","sources","``","(","batch",",","src_len",",","dim","``","Returns",":","FloatTensor",":","raw","attention","scores","(","unnormalized",")","for","each","src","index","``","(","batch",",","tgt_len",",","src_len",")","``"]
code: def score(self, h_t, h_s):
      """
      Args:
        h_t (FloatTensor): sequence of queries ``(batch, tgt_len, dim)``
        h_s (FloatTensor): sequence of sources ``(batch, src_len, dim``
  
      Returns:
        FloatTensor: raw attention scores (unnormalized) for each src index
          ``(batch, tgt_len, src_len)``
      """
      src_batch, src_len, src_dim = h_s.size()
      tgt_batch, tgt_len, tgt_dim = h_t.size()
  
      if self.attn_type in ["general", "dot"]:
          if self.attn_type == "general":
              h_t = self.linear_in(h_t)
          h_s_ = h_s.transpose(1, 2)
          # (batch, t_len, d) x (batch, d, s_len) --> (batch, t_len, s_len)
          return torch.bmm(h_t, h_s_)
      else:
          dim = self.dim
          wq = self.linear_query(h_t)
          wq = wq.view(tgt_batch, tgt_len, 1, dim)
          wq = wq.expand(tgt_batch, tgt_len, src_len, dim)
  
          uh = self.linear_context(h_s.contiguous())
          uh = uh.view(src_batch, 1, src_len, dim)
          uh = uh.expand(src_batch, tgt_len, src_len, dim)
  
          # (batch, t_len, s_len, d)
          wquh = torch.tanh(wq + uh)
  
          return self.v(wquh).view(tgt_batch, tgt_len, src_len)
  
file_path: OpenNMT-py/onmt/modules/global_attention.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from onmt.modules.sparse_activations import sparsemax
  from onmt.utils.misc import sequence_mask
label_desc: Use image node_id 2 for calling the GlobalAttention obj's underlying member method code with example usage: obj.score(h_t, h_s) and returns: torch, self