class_docstr: This module computes the self-attention, similar to the architecture in BERT. Additionally, the attention
  scoring function can be specified.
  Details in the paper:
  [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding, Devlin et al, 2019]
  (https://api.semanticscholar.org/CorpusID:52967399)
  
  # Parameters
  
  hidden_size: `int`
  num_attention_heads: `int`
  dropout: `float` (default = `0.0`)
  scoring_func: `str` (default = `scaled_dot_product`)
      The name of the attention-calculating function to be used.
      Eg. `additive`, `linear`, etc. For a complete list, please check
      :mod:`allennlp.modules.attention.attention`.
class_docstr_tok: ["This","module","computes","the","self-attention",",","similar","to","the","architecture","in","BERT",".","Additionally",",","the","attention","scoring","function","can","be","specified",".","Details","in","the","paper",":","[","BERT",":","Pre-training","of","Deep","Bidirectional","Transformers","for","Language","Understanding",",","Devlin","et","al",",","2019","]","(","https",":","\/\/api.semanticscholar.org\/CorpusID:52967399",")","#","Parameters","hidden_size",":","`","int","`","num_attention_heads",":","`","int","`","dropout",":","`","float","`","(","default","=","`","0.0","`",")","scoring_func",":","`","str","`","(","default","=","`","scaled_dot_product","`",")","The","name","of","the","attention-calculating","function","to","be","used",".","Eg",".","`","additive","`",",","`","linear","`",",","etc",".","For","a","complete","list",",","please","check",":","mod",":","`","allennlp.modules.attention.attention","`","."]
code: def __init__(
      self,
      hidden_size: int,
      num_attention_heads: int,
      dropout: float = 0.0,
      scoring_func: str = "scaled_dot_product",
      output_linear: bool = False,
      is_decoder: bool = False,
      is_cross_attention: bool = False,
  ):
      attention_head_size = int(hidden_size / num_attention_heads)
  
      super().__init__(
          hidden_size=hidden_size,
          attention_head_size=attention_head_size,
          num_attention_heads=num_attention_heads,
          scoring_func=scoring_func,
          output_linear=output_linear,
          dropout=dropout,
          bias=True,
          is_decoder=is_decoder,
          is_cross_attention=is_cross_attention,
      )
  
imports: import math
  from typing import Optional, Tuple, TYPE_CHECKING
  from dataclasses import dataclass
  import torch
  import torch.nn.functional
  from allennlp.common import FromParams
  from allennlp.common.checks import ConfigurationError
  from allennlp.modules.matrix_attention.matrix_attention import MatrixAttention
  from allennlp.modules.transformer.transformer_module import TransformerModule
  from allennlp.modules.transformer.util import apply_mask, FloatT, IntT, BoolT
label_desc: Use image node_id 1 to create a new SelfAttention object from inherited base classes: AttentionModule with example: obj = SelfAttention(hidden_size, num_attention_heads, dropout, scoring_func, output_linear, is_decoder, is_cross_attention)