class_docstr: The Scaled Dot Production Attention operation from `Attention Is All You Need <https://arxiv.org/abs/1706.03762>_` paper.
  
  Example
  -------
  >>> from deepchem.models import ScaledDotProductAttention as SDPA
  >>> attn = SDPA()
  >>> x = torch.ones(1, 5)
  >>> # Linear layers for making query, key, value
  >>> Q, K, V = nn.Parameter(torch.ones(5)), nn.Parameter(torch.ones(5)), nn.Parameter(torch.ones(5))
  >>> query, key, value = Q * x, K * x, V * x
  >>> x_out, attn_score = attn(query, key, value)
class_docstr_tok: ["The","Scaled","Dot","Production","Attention","operation","from","`","Attention","Is","All","You","Need","<","https",":","\/\/arxiv.org\/abs\/1706.03762",">","_","`","paper",".","Example","--","--","--","-",">",">",">","from","deepchem.models","import","ScaledDotProductAttention","as","SDPA",">",">",">","attn","=","SDPA","(",")",">",">",">","x","=","torch.ones","(","1",",","5",")",">",">",">","#","Linear","layers","for","making","query",",","key",",","value",">",">",">","Q",",","K",",","V","=","nn.Parameter","(","torch.ones","(","5",")",")",",","nn.Parameter","(","torch.ones","(","5",")",")",",","nn.Parameter","(","torch.ones","(","5",")",")",">",">",">","query",",","key",",","value","=","Q","*","x",",","K","*","x",",","V","*","x",">",">",">","x_out",",","attn_score","=","attn","(","query",",","key",",","value",")"]
docstr: Parameters
  ----------
  query: torch.Tensor
      Query tensor for attention
  key: torch.Tensor
      Key tensor for attention
  value: torch.Tensor
      Value tensor for attention
  mask: torch.Tensor (optional)
      Mask to apply during attention computation
  dropout: nn.Dropout (optional)
      Dropout layer for attention output
docstr_tok: ["Parameters","--","--","--","--","--","query",":","torch.Tensor","Query","tensor","for","attention","key",":","torch.Tensor","Key","tensor","for","attention","value",":","torch.Tensor","Value","tensor","for","attention","mask",":","torch.Tensor","(","optional",")","Mask","to","apply","during","attention","computation","dropout",":","nn.Dropout","(","optional",")","Dropout","layer","for","attention","output"]
code: def forward(
      self,
      query: torch.Tensor,
      key: torch.Tensor,
      value: torch.Tensor,
      mask: Optional[torch.Tensor] = None,
      dropout: Optional[nn.Dropout] = None,
  ):
      """
      Parameters
      ----------
      query: torch.Tensor
          Query tensor for attention
      key: torch.Tensor
          Key tensor for attention
      value: torch.Tensor
          Value tensor for attention
      mask: torch.Tensor (optional)
          Mask to apply during attention computation
      dropout: nn.Dropout (optional)
          Dropout layer for attention output
      """
      d_k = query.size(-1)
      scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(
          d_k
      )
  
      if mask is not None:
          scores = scores.masked_fill(mask == 0, self.epsilon)
  
      p_attn = scores.softmax(dim=-1)
      if dropout is not None:
          p_attn = dropout(p_attn)
  
      return torch.matmul(p_attn, value), p_attn
  
file_path: deepchem/deepchem/models/torch_models/attention.py
imports: import math
  from typing import Optional
label_desc: Use image node_id 2 for calling the ScaledDotProductAttention obj's underlying member method code with example usage: obj.forward(query, key, value, mask, dropout) and returns: torch,  p_attn