class_docstr: StdTreeDecoder: This is a tree decoder implementation, which is used for tree object decoding.
  
  Attributes
  ----------
  attn_type : str,
      Describe which attention mechanism is used, can be ``uniform``,
      ``separate_on_encoder_type``, ``separate_on_node_type``.
  
  embeddings : torch.nn.Module,
      Embedding layer, input is tensor of word index, output is word embedding tensor.
  
  enc_hidden_size : int,
      Size of encoder hidden state.
  
  dec_emb_size : int,
      Size of decoder word embedding layer output size.
  
  dec_hidden_size : int,
      Size of decoder hidden state. (namely the ``lstm`` or ``gru``
      hidden size when rnn unit has been specified)
  
  output_size : int,
      Size of output vocabulary size.
  
  teacher_force_ratio : float,
      The ratio of possibility to use teacher force training.
  
  use_sibling : boolean,
      Whether feed sibling state in each decoding step.
  
  use_copy : boolean,
      Whether use copy mechanism in decoding.
  
  fuse_strategy: str, option=[None, "average", "concatenate"], default=None
      The strategy to fuse attention results generated by separate attention.
      "None": If we do ``uniform`` attention, we will set it to None.
      "``average``": We will take an average on all results.
      "``concatenate``": We will concatenate all results to one.
  
  num_layers : int, optional,
      Layer number of decoder rnn unit.
  
  dropout_for_decoder: float,
      Dropout ratio for decoder(include both the dropout for word embedding
      and the dropout for attention layer)
  
  tgt_vocab : object,
      The vocab object used in decoder, including all the word<->id pairs
      appeared in the output sentences.
  
  graph_pooling_strategy : str,
      The graph pooling strategy used to generate the graph embedding with node embeddings
  
  rnn_type: str, optional,
      The rnn unit is used, option=["lstm", "gru"], default="lstm".
  
  max_dec_seq_length : int, optional,
      In decoding, the decoding steps upper limit.
  
  max_dec_tree_depth : int, optional,
      In decoding, the tree depth lower limit.
docstr: The decoding function in tree decoder.
  
  Parameters
  ----------
  tgt_batch_size : int,
      batch size.
  dec_single_input : torch.Tensor,
      word id matrix for decoder input: [B, N].
  dec_single_state : torch.Tensor
      the rnn decoding hidden state: [B, N, D].
  memory : torch.Tensor
      the encoder output node embedding.
  parent_state : torch.Tensor
      the parent embedding used in parent feeding mechanism.
  input_mask : torch.Tensor, optional
      input mask, by default None
  memory_mask : torch.Tensor, optional
      mask for encoder output, by default None
  memory_candidate : torch.Tensor, optional
      encoder output used for separate attention mechanism, by default None
  sibling_state : torch.Tensor, optional
      sibling state for sibling feeding mechanism, by default None
  oov_dict : object, optional
      out-of-vocabulary object for copy mechanism, by default None
  enc_batch : torch.Tensor,
      The input batch : (Batch_size * Source sentence word index tensor).
docstr_tok: ["The","decoding","function","in","tree","decoder",".","Parameters","--","--","--","--","--","tgt_batch_size",":","int",",","batch","size",".","dec_single_input",":","torch.Tensor",",","word","id","matrix","for","decoder","input",":","[","B",",","N","]",".","dec_single_state",":","torch.Tensor","the","rnn","decoding","hidden","state",":","[","B",",","N",",","D","]",".","memory",":","torch.Tensor","the","encoder","output","node","embedding",".","parent_state",":","torch.Tensor","the","parent","embedding","used","in","parent","feeding","mechanism",".","input_mask",":","torch.Tensor",",","optional","input","mask",",","by","default","None","memory_mask",":","torch.Tensor",",","optional","mask","for","encoder","output",",","by","default","None","memory_candidate",":","torch.Tensor",",","optional","encoder","output","used","for","separate","attention","mechanism",",","by","default","None","sibling_state",":","torch.Tensor",",","optional","sibling","state","for","sibling","feeding","mechanism",",","by","default","None","oov_dict",":","object",",","optional","out-of-vocabulary","object","for","copy","mechanism",",","by","default","None","enc_batch",":","torch.Tensor",",","The","input","batch",":","(","Batch_size","*","Source","sentence","word","index","tensor",")","."]
code: def decode_step(
      self,
      tgt_batch_size,
      dec_single_input,
      dec_single_state,
      memory,
      parent_state,
      input_mask=None,
      memory_mask=None,
      memory_candidate=None,
      sibling_state=None,
      oov_dict=None,
      enc_batch=None,
  ):
      """The decoding function in tree decoder.
  
      Parameters
      ----------
      tgt_batch_size : int,
          batch size.
      dec_single_input : torch.Tensor,
          word id matrix for decoder input: [B, N].
      dec_single_state : torch.Tensor
          the rnn decoding hidden state: [B, N, D].
      memory : torch.Tensor
          the encoder output node embedding.
      parent_state : torch.Tensor
          the parent embedding used in parent feeding mechanism.
      input_mask : torch.Tensor, optional
          input mask, by default None
      memory_mask : torch.Tensor, optional
          mask for encoder output, by default None
      memory_candidate : torch.Tensor, optional
          encoder output used for separate attention mechanism, by default None
      sibling_state : torch.Tensor, optional
          sibling state for sibling feeding mechanism, by default None
      oov_dict : object, optional
          out-of-vocabulary object for copy mechanism, by default None
      enc_batch : torch.Tensor,
          The input batch : (Batch_size * Source sentence word index tensor).
      """
      device = memory.device
  
      dec_single_input = self._filter_oov(
          dec_single_input, self.tgt_vocab
      )
      rnn_state_c, rnn_state_h, dec_emb = self.rnn(
          dec_single_input,
          dec_single_state[0],
          dec_single_state[1],
          parent_state,
          sibling_state,
      )
  
      attn_collect = []
      score_collect = []
  
      if self.separate_attn:
          pass
      else:
          context_vector, attn_scores = self.attention(
              query=rnn_state_h, memory=memory
          )
          attn_collect.append(context_vector)
          score_collect.append(attn_scores)
  
      pred = F.tanh(
          self.linear_att(torch.cat((context_vector, rnn_state_h), 1))
      )
      decoder_output = self.linear_out(self.dropout_attn(pred))
      if self.use_copy:
          assert enc_batch is not None
          assert oov_dict is not None
          output = torch.zeros(tgt_batch_size, oov_dict.vocab_size).to(
              device
          )
          attn_ptr = torch.cat(attn_collect, dim=-1)
  
          pgen_collect = [
              dec_emb,
              torch.cat((rnn_state_c, rnn_state_h), -1),
              attn_ptr,
          ]
          prob_ptr = torch.sigmoid(
              self.ptr(torch.cat(pgen_collect, -1))
          )
          prob_gen = 1 - prob_ptr
          gen_output = torch.softmax(decoder_output, dim=-1)
  
          ret = prob_gen * gen_output
          need_pad_length = len(oov_dict) - len(self.tgt_vocab)
          output = torch.cat(
              (ret, ret.new_zeros((tgt_batch_size, need_pad_length))),
              dim=1,
          )
          # output[:, :self.tgt_vocab.vocab_size] = ret
  
          ptr_output = attn_scores
          output.scatter_add_(1, enc_batch, prob_ptr * ptr_output)
          decoder_output = output
          # decoder_output = -F.threshold(-output, -1.0, -1.0)
      else:
          decoder_output = torch.softmax(decoder_output, dim=-1)
  
      return decoder_output, (rnn_state_c, rnn_state_h), attn_scores
  
imports: import random
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from graph4nlp.pytorch.modules.utils.tree_utils import Tree, to_cuda
  from .attention import Attention
  from .base import RNNTreeDecoderBase
label_desc: Use image node_id 4 for calling the StdTreeDecoder obj's underlying member method code with example usage: obj.decode_step(tgt_batch_size, dec_single_input, dec_single_state, memory, parent_state, input_mask, memory_mask, memory_candidate, sibling_state, oov_dict, enc_batch) and returns: decoder_output,  rnn_state_c,  rnn_state_h,  attn_scores