class_docstr: Implements a stacked self-attention encoder similar to the Transformer
  architecture in `Attention is all you Need
  <https://www.semanticscholar.org/paper/Attention-Is-All-You-Need-Vaswani-Shazeer/0737da0767d77606169cbf4187b83e1ab62f6077>`_ .
  
  This encoder combines 3 layers in a 'block':
  
  1. A 2 layer FeedForward network.
  2. Multi-headed self attention, which uses 2 learnt linear projections
     to perform a dot-product similarity between every pair of elements
     scaled by the square root of the sequence length.
  3. Layer Normalisation.
  
  These are then stacked into ``num_layers`` layers.
  
  Parameters
  ----------
  input_dim : ``int``, required.
      The input dimension of the encoder.
  hidden_dim : ``int``, required.
      The hidden dimension used for the _input_ to self attention layers
      and the _output_ from the feedforward layers.
  projection_dim : ``int``, required.
      The dimension of the linear projections for the self-attention layers.
  feedforward_hidden_dim : ``int``, required.
      The middle dimension of the FeedForward network. The input and output
      dimensions are fixed to ensure sizes match up for the self attention layers.
  num_layers : ``int``, required.
      The number of stacked self attention -> feedfoward -> layer normalisation blocks.
  num_attention_heads : ``int``, required.
      The number of attention heads to use per layer.
  use_positional_encoding: ``bool``, optional, (default = True)
      Whether to add sinusoidal frequencies to the input tensor. This is strongly recommended,
      as without this feature, the self attention layers have no idea of absolute or relative
      position (as they are just computing pairwise similarity between vectors of elements),
      which can be important features for many tasks.
  dropout_prob : ``float``, optional, (default = 0.1)
      The dropout probability for the feedforward network.
  residual_dropout_prob : ``float``, optional, (default = 0.2)
      The dropout probability for the residual connections.
  attention_dropout_prob : ``float``, optional, (default = 0.1)
      The dropout probability for the attention distributions in each attention layer.
class_docstr_tok: ["Implements","a","stacked","self-attention","encoder","similar","to","the","Transformer","architecture","in","`","Attention","is","all","you","Need","<","https",":","\/\/www.semanticscholar.org\/paper\/Attention-Is-All-You-Need-Vaswani-Shazeer\/0737da0767d77606169cbf4187b83e1ab62f6077",">","`","_",".","This","encoder","combines","3","layers","in","a","'block","'",":","1",".","A","2","layer","FeedForward","network",".","2",".","Multi-headed","self","attention",",","which","uses","2","learnt","linear","projections","to","perform","a","dot-product","similarity","between","every","pair","of","elements","scaled","by","the","square","root","of","the","sequence","length",".","3",".","Layer","Normalisation",".","These","are","then","stacked","into","``","num_layers","``","layers",".","Parameters","--","--","--","--","--","input_dim",":","``","int","``",",","required",".","The","input","dimension","of","the","encoder",".","hidden_dim",":","``","int","``",",","required",".","The","hidden","dimension","used","for","the","_input_","to","self","attention","layers","and","the","_output_","from","the","feedforward","layers",".","projection_dim",":","``","int","``",",","required",".","The","dimension","of","the","linear","projections","for","the","self-attention","layers",".","feedforward_hidden_dim",":","``","int","``",",","required",".","The","middle","dimension","of","the","FeedForward","network",".","The","input","and","output","dimensions","are","fixed","to","ensure","sizes","match","up","for","the","self","attention","layers",".","num_layers",":","``","int","``",",","required",".","The","number","of","stacked","self","attention","-",">","feedfoward","-",">","layer","normalisation","blocks",".","num_attention_heads",":","``","int","``",",","required",".","The","number","of","attention","heads","to","use","per","layer",".","use_positional_encoding",":","``","bool","``",",","optional",",","(","default","=","True",")","Whether","to","add","sinusoidal","frequencies","to","the","input","tensor",".","This","is","strongly","recommended",",","as","without","this","feature",",","the","self","attention","layers","have","no","idea","of","absolute","or","relative","position","(","as","they","are","just","computing","pairwise","similarity","between","vectors","of","elements",")",",","which","can","be","important","features","for","many","tasks",".","dropout_prob",":","``","float","``",",","optional",",","(","default","=","0.1",")","The","dropout","probability","for","the","feedforward","network",".","residual_dropout_prob",":","``","float","``",",","optional",",","(","default","=","0.2",")","The","dropout","probability","for","the","residual","connections",".","attention_dropout_prob",":","``","float","``",",","optional",",","(","default","=","0.1",")","The","dropout","probability","for","the","attention","distributions","in","each","attention","layer","."]
code: def get_output_dim(self):
      return self._output_dim
  
file_path: magnitude/pymagnitude/third_party/allennlp/modules/seq2seq_encoders/stacked_self_attention.py
imports: from __future__ import absolute_import
  import torch
  from torch.nn import Dropout
  from allennlp.modules.feedforward import FeedForward
  from allennlp.modules.layer_norm import LayerNorm
  from allennlp.modules.seq2seq_encoders.multi_head_self_attention import MultiHeadSelfAttention
  from allennlp.modules.seq2seq_encoders.seq2seq_encoder import Seq2SeqEncoder
  from allennlp.nn.activations import Activation
  from allennlp.nn.util import add_positional_features
label_desc: Use image node_id 3 for calling the StackedSelfAttentionEncoder obj's underlying member method code with example usage: obj.get_output_dim() and returns: self