original_docstring: Maps a query and a set of key-value pairs to an output.
  
          Args:
              query (torch.Tensor): [description]
              key (torch.Tensor): [description]
              value (torch.Tensor): [description]
              mask (optional): [description]. Defaults to None.
  
          Returns:
              attn_output: attention output.
          
docstring: Maps a query and a set of key-value pairs to an output.
docstring_tokens: Maps a query and a set of key - value pairs to an output .
code: def forward(self, query, key, value, mask=None):
          """Maps a query and a set of key-value pairs to an output.
  
          Args:
              query (torch.Tensor): [description]
              key (torch.Tensor): [description]
              value (torch.Tensor): [description]
              mask (optional): [description]. Defaults to None.
  
          Returns:
              attn_output: attention output.
          """
          if mask is not None:
              # Same mask applied to all nhead heads.
              mask = mask.unsqueeze(1)
          nbatches = query.size(0)
  
          # Do all the linear projections in batch from d_model => h x d_k
          query, key, value = [l(x).view(nbatches, -1, self.nhead, self.d_k)
                               for l, x in zip(self.linears, (query, key, value))]
  
          # Apply attention on all the projected vectors in batch.
          x, self.atnn = attention(query, key, value, mask, self.dropout)
  
          # Transpose x from (batch_size, seq_length, nhead, d_k)
          # to (batch_size, nhead, seq_length, d_k) and
          # concats using a view and apply a final linear.
          x = x.transpose(1, 2).contiguous()
          x = x.view(nbatches, -1, self.nhead * self.d_k)
          attn_output = self.linears[-1](x)
          return attn_output
code_tokens: def forward ( self , query , key , value , mask = None ) : if mask is not None : mask = mask . unsqueeze ( 1 ) nbatches = query . size ( 0 ) query , key , value = [ l ( x ) . view ( nbatches , - 1 , self . nhead , self . d_k ) for l , x in zip ( self . linears , ( query , key , value ) ) ] x , self . atnn = attention ( query , key , value , mask , self . dropout ) x = x . transpose ( 1 , 2 ) . contiguous ( ) x = x . view ( nbatches , - 1 , self . nhead * self . d_k ) attn_output = self . linears [ - 1 ] ( x ) return attn_output
short_docstring: Maps a query and a set of key-value pairs to an output.
short_docstring_tokens: Maps a query and a set of key - value pairs to an output .
comment: """Maps a query and a set of key-value pairs to an output.
  
          Args:
              query (torch.Tensor): [description]
              key (torch.Tensor): [description]
              value (torch.Tensor): [description]
              mask (optional): [description]. Defaults to None.
  
          Returns:
              attn_output: attention output.
          """$SEP$# Same mask applied to all nhead heads.$SEP$# Do all the linear projections in batch from d_model => h x d_k$SEP$# Apply attention on all the projected vectors in batch.$SEP$# Transpose x from (batch_size, seq_length, nhead, d_k)$SEP$# to (batch_size, nhead, seq_length, d_k) and$SEP$# concats using a view and apply a final linear.