class_docstr: Self-attention module with q,k,v from the same input
  
  Parameters
  ----------
  d_hidden : int
      hidden dimension
  n_head : int, optional
      number of attention heads, by default 1
  bias : bool, optional
      add bias term in input and output projections, by default True
  bidirectional : bool, optional
      if False, add a mask to avoid backward attention, by default False
  apply_rel_dist : Optional[str], optional
      add relative distance embeddings to dot-product attention, can be
          'add' (linearly combine key and dist),
          'dot' (dot product between key and dist),
          or None (disabled),
      by default None
  share_values : bool, optional
      if True, a value reprensentation is shared by all attention heads, by default False
      ref. https://arxiv.org/abs/1912.09363
  dropout : float, optional
      dropout rate, by default 0.0
  temperature : float, optional
      softmax temperature, by default 1.0
class_docstr_tok: ["Self-attention","module","with","q",",","k",",","v","from","the","same","input","Parameters","--","--","--","--","--","d_hidden",":","int","hidden","dimension","n_head",":","int",",","optional","number","of","attention","heads",",","by","default","1","bias",":","bool",",","optional","add","bias","term","in","input","and","output","projections",",","by","default","True","bidirectional",":","bool",",","optional","if","False",",","add","a","mask","to","avoid","backward","attention",",","by","default","False","apply_rel_dist",":","Optional","[","str","]",",","optional","add","relative","distance","embeddings","to","dot-product","attention",",","can","be","'add","'","(","linearly","combine","key","and","dist",")",",","'dot","'","(","dot","product","between","key","and","dist",")",",","or","None","(","disabled",")",",","by","default","None","share_values",":","bool",",","optional","if","True",",","a","value","reprensentation","is","shared","by","all","attention","heads",",","by","default","False","ref",".","https",":","\/\/arxiv.org\/abs\/1912.09363","dropout",":","float",",","optional","dropout","rate",",","by","default","0.0","temperature",":","float",",","optional","softmax","temperature",",","by","default","1.0"]
code: def forward(
      self, x: Tensor, *, mask: Optional[BoolTensor] = None
  ) -> Tensor:
      q, k, v = self._compute_qkv(x)
      score = self._compute_attn_score(q, k, mask)
      v = self._compute_attn_output(score, v)
      return v
  
imports: from typing import Tuple, Optional
  import math
  import torch
  from torch import Tensor, BoolTensor
  from torch import nn
  from torch.nn import init
  from torch.nn.functional import linear, conv1d
  from .base import Attention
  from .posemb import SinusoidalPositionalEmbedding
label_desc: Use image node_id 7 for calling the SelfAttention obj's underlying member method code with example usage: obj.forward(x) and returns: v