class_docstr: LSTM decoder.
code: def __init__(
      self,
      dictionary,
      embed_dim=512,
      hidden_size=512,
      out_embed_dim=512,
      num_layers=1,
      dropout_in=0.1,
      dropout_out=0.1,
      attention=True,
      encoder_output_units=512,
      pretrained_embed=None,
      share_input_output_embed=False,
      adaptive_softmax_cutoff=None,
      max_target_positions=DEFAULT_MAX_TARGET_POSITIONS,
      residuals=False,
  ):
      super().__init__(dictionary)
      self.dropout_in_module = FairseqDropout(
          dropout_in * 1.0, module_name=self.__class__.__name__
      )
      self.dropout_out_module = FairseqDropout(
          dropout_out * 1.0, module_name=self.__class__.__name__
      )
      self.hidden_size = hidden_size
      self.share_input_output_embed = share_input_output_embed
      self.need_attn = True
      self.max_target_positions = max_target_positions
      self.residuals = residuals
      self.num_layers = num_layers
  
      self.adaptive_softmax = None
      num_embeddings = len(dictionary)
      padding_idx = dictionary.pad()
      if pretrained_embed is None:
          self.embed_tokens = Embedding(
              num_embeddings, embed_dim, padding_idx
          )
      else:
          self.embed_tokens = pretrained_embed
  
      self.encoder_output_units = encoder_output_units
      if (
          encoder_output_units != hidden_size
          and encoder_output_units != 0
      ):
          self.encoder_hidden_proj = Linear(
              encoder_output_units, hidden_size
          )
          self.encoder_cell_proj = Linear(
              encoder_output_units, hidden_size
          )
      else:
          self.encoder_hidden_proj = self.encoder_cell_proj = None
  
      # disable input feeding if there is no encoder
      # input feeding is described in arxiv.org/abs/1508.04025
      input_feed_size = 0 if encoder_output_units == 0 else hidden_size
      self.layers = nn.ModuleList(
          [
              LSTMCell(
                  input_size=input_feed_size + embed_dim
                  if layer == 0
                  else hidden_size,
                  hidden_size=hidden_size,
              )
              for layer in range(num_layers)
          ]
      )
  
      if attention:
          # TODO make bias configurable
          self.attention = AttentionLayer(
              hidden_size, encoder_output_units, hidden_size, bias=False
          )
      else:
          self.attention = None
  
      if hidden_size != out_embed_dim:
          self.additional_fc = Linear(hidden_size, out_embed_dim)
  
      if adaptive_softmax_cutoff is not None:
          # setting adaptive_softmax dropout to dropout_out for now but can be redefined
          self.adaptive_softmax = AdaptiveSoftmax(
              num_embeddings,
              hidden_size,
              adaptive_softmax_cutoff,
              dropout=dropout_out,
          )
      elif not self.share_input_output_embed:
          self.fc_out = Linear(
              out_embed_dim, num_embeddings, dropout=dropout_out
          )
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import utils
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, FairseqIncrementalDecoder, register_model, register_model_architecture
  from fairseq.modules import AdaptiveSoftmax, FairseqDropout
  from torch import Tensor
label_desc: Use image node_id 1 to create a new LSTMDecoder object from inherited base classes: FairseqIncrementalDecoder with example: obj = LSTMDecoder(dictionary, embed_dim, hidden_size, out_embed_dim, num_layers, dropout_in, dropout_out, attention, encoder_output_units, pretrained_embed, share_input_output_embed, adaptive_softmax_cutoff, max_target_positions, residuals)