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 _from_config(cls, config: "PretrainedConfig", **kwargs):
      final_kwargs = {}
      final_kwargs["hidden_size"] = config.hidden_size
      final_kwargs["num_attention_heads"] = config.num_attention_heads
      final_kwargs["output_linear"] = hasattr(
          config, "n_heads"
      )  # This is the distilbert case; they have a linear layer as the output.
      if hasattr(config, "attention_dropout"):
          final_kwargs["dropout"] = config.attention_dropout
      else:
          final_kwargs["dropout"] = config.attention_probs_dropout_prob
      final_kwargs.update(**kwargs)
      return cls(**final_kwargs)
  
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 2 for calling the SelfAttention obj's underlying member method code with example usage: obj._from_config(cls, config) and returns: cls