(self, h_t, h_s)
Args:
          h_t (`FloatTensor`): sequence of queries `[batch x tgt_len x dim]`
          h_s (`FloatTensor`): sequence of sources `[batch x src_len x dim]`

        Returns:
          :obj:`FloatTensor`:
           raw attention scores (unnormalized) for each src index
          `[batch x tgt_len x src_len]`
Args:
          h_t (`FloatTensor`): sequence of queries `[batch x tgt_len x dim]`
          h_s (`FloatTensor`): sequence of sources `[batch x src_len x dim]`
Args : h_t ( FloatTensor ) : sequence of queries [ batch x tgt_len x dim ] h_s ( FloatTensor ) : sequence of sources [ batch x src_len x dim ]
def score(self, h_t, h_s):
        """
        Args:
          h_t (`FloatTensor`): sequence of queries `[batch x tgt_len x dim]`
          h_s (`FloatTensor`): sequence of sources `[batch x src_len x dim]`

        Returns:
          :obj:`FloatTensor`:
           raw attention scores (unnormalized) for each src index
          `[batch x tgt_len x src_len]`

        """

        # Check input sizes
        src_batch, src_len, src_dim = h_s.size()
        tgt_batch, tgt_len, tgt_dim = h_t.size()
        aeq(src_batch, tgt_batch)
        aeq(src_dim, tgt_dim)
        aeq(self.dim, src_dim)

        if self.attn_type in ["general", "dot"]:
            if self.attn_type == "general":
                h_t_ = h_t.view(tgt_batch * tgt_len, tgt_dim)
                h_t_ = self.linear_in(h_t_)
                h_t = h_t_.view(tgt_batch, tgt_len, tgt_dim)
            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.view(-1, dim))
            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().view(-1, dim))
            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(-1, dim)).view(tgt_batch, tgt_len, src_len)
def score ( self , h_t , h_s ) : # Check input sizes src_batch , src_len , src_dim = h_s . size ( ) tgt_batch , tgt_len , tgt_dim = h_t . size ( ) aeq ( src_batch , tgt_batch ) aeq ( src_dim , tgt_dim ) aeq ( self . dim , src_dim ) if self . attn_type in [ "general" , "dot" ] : if self . attn_type == "general" : h_t_ = h_t . view ( tgt_batch * tgt_len , tgt_dim ) h_t_ = self . linear_in ( h_t_ ) h_t = h_t_ . view ( tgt_batch , tgt_len , tgt_dim ) 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 . view ( - 1 , dim ) ) 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 ( ) . view ( - 1 , dim ) ) 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 ( - 1 , dim ) ) . view ( tgt_batch , tgt_len , src_len )