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 private calculation method for decoder.
  
  Parameters
  ----------
  enc_batch : torch.Tensor,
      The input batch : (Batch_size * Source sentence word index tensor).
  
  tgt_tree_batch:
      The target tree to generate : consists of (Batch_size * Tree object),
      each node in a Tree object is either a word index or a children Tree object.
  
  graph_node_embedding: torch.Tensor,
      The graph node embedding matrix of shape :math:`(B, N, D_{in})`
  
  graph_node_mask: torch.Tensor,
      The graph node type mask matrix of shape :math`(B, N)`
  
  rnn_node_embedding: torch.Tensor,
      The rnn encoded embedding matrix of shape :math`(B, N, D_{in})`
  
  graph_level_embedding: torch.Tensor,
      graph level embedding of shape :math`(B, D_{in})`
  
  graph_edge_embedding: torch.Tensor,
      graph edge embedding of shape :math`(B, N, D_{in})`
  
  graph_edge_mask: torch.Tensor,
      graph edge type embedding
  
  oov_dict: dict,
      vocab dict used in copy mechanism to incorporate some new words which
      have never appeared in vocab for input sentences in training set.
docstr_tok: ["The","private","calculation","method","for","decoder",".","Parameters","--","--","--","--","--","enc_batch",":","torch.Tensor",",","The","input","batch",":","(","Batch_size","*","Source","sentence","word","index","tensor",")",".","tgt_tree_batch",":","The","target","tree","to","generate",":","consists","of","(","Batch_size","*","Tree","object",")",",","each","node","in","a","Tree","object","is","either","a","word","index","or","a","children","Tree","object",".","graph_node_embedding",":","torch.Tensor",",","The","graph","node","embedding","matrix","of","shape",":","math",":","`","(","B",",","N",",","D_","{","in","}",")","`","graph_node_mask",":","torch.Tensor",",","The","graph","node","type","mask","matrix","of","shape",":","math","`","(","B",",","N",")","`","rnn_node_embedding",":","torch.Tensor",",","The","rnn","encoded","embedding","matrix","of","shape",":","math","`","(","B",",","N",",","D_","{","in","}",")","`","graph_level_embedding",":","torch.Tensor",",","graph","level","embedding","of","shape",":","math","`","(","B",",","D_","{","in","}",")","`","graph_edge_embedding",":","torch.Tensor",",","graph","edge","embedding","of","shape",":","math","`","(","B",",","N",",","D_","{","in","}",")","`","graph_edge_mask",":","torch.Tensor",",","graph","edge","type","embedding","oov_dict",":","dict",",","vocab","dict","used","in","copy","mechanism","to","incorporate","some","new","words","which","have","never","appeared","in","vocab","for","input","sentences","in","training","set","."]
code: def _run_forward_pass(
      self,
      graph_node_embedding,
      graph_node_mask,
      rnn_node_embedding,
      graph_level_embedding,
      graph_edge_embedding=None,
      graph_edge_mask=None,
      tgt_tree_batch=None,
      enc_batch=None,
      oov_dict=None,
  ):
      r"""
          The private calculation method for decoder.
  
      Parameters
      ----------
      enc_batch : torch.Tensor,
          The input batch : (Batch_size * Source sentence word index tensor).
  
      tgt_tree_batch:
          The target tree to generate : consists of (Batch_size * Tree object),
          each node in a Tree object is either a word index or a children Tree object.
  
      graph_node_embedding: torch.Tensor,
          The graph node embedding matrix of shape :math:`(B, N, D_{in})`
  
      graph_node_mask: torch.Tensor,
          The graph node type mask matrix of shape :math`(B, N)`
  
      rnn_node_embedding: torch.Tensor,
          The rnn encoded embedding matrix of shape :math`(B, N, D_{in})`
  
      graph_level_embedding: torch.Tensor,
          graph level embedding of shape :math`(B, D_{in})`
  
      graph_edge_embedding: torch.Tensor,
          graph edge embedding of shape :math`(B, N, D_{in})`
  
      graph_edge_mask: torch.Tensor,
          graph edge type embedding
  
      oov_dict: dict,
          vocab dict used in copy mechanism to incorporate some new words which
          have never appeared in vocab for input sentences in training set.
      """
      tgt_batch_size = len(tgt_tree_batch)
  
      enc_outputs = graph_node_embedding
      device = graph_node_embedding.device
  
      if graph_level_embedding is None:
          if self.graph_pooling_strategy == "max":
              graph_level_embedding = torch.max(
                  graph_node_embedding, 1
              )[0]
          elif self.graph_pooling_strategy == "min":
              graph_level_embedding = torch.min(
                  graph_node_embedding, 1
              )[0]
          elif self.graph_pooling_strategy == "mean":
              graph_level_embedding = torch.mean(
                  graph_node_embedding, 1
              )
          else:
              raise NotImplementedError()
  
          graph_cell_state = graph_level_embedding
          graph_hidden_state = graph_level_embedding
      else:
          graph_cell_state, graph_hidden_state = graph_level_embedding
  
      # rnn_node_embedding = torch.zeros_like(graph_node_embedding,
      #   requires_grad=False).to(device)
  
      cur_index = 1
      loss = 0
  
      dec_batch, queue_tree, max_index = get_dec_batch(
          tgt_tree_batch, tgt_batch_size, device, self.tgt_vocab
      )
  
      dec_state = {}
      for i in range(self.max_dec_tree_depth + 1):
          dec_state[i] = {}
          for j in range(self.max_dec_seq_length + 1):
              dec_state[i][j] = {}
  
      while cur_index <= max_index:
          if cur_index > self.max_dec_tree_depth:
              break
          for j in range(1, 3):
              dec_state[cur_index][0][j] = torch.zeros(
                  (tgt_batch_size, self.rnn_size),
                  dtype=torch.float,
                  requires_grad=False,
              ).to(device)
  
          sibling_state = torch.zeros(
              (tgt_batch_size, self.rnn_size),
              dtype=torch.float,
              requires_grad=False,
          ).to(device)
  
          # with torch.no_grad():
          if cur_index == 1:
              for i in range(tgt_batch_size):
                  dec_state[1][0][1][i, :] = graph_cell_state[i]
                  dec_state[1][0][2][i, :] = graph_hidden_state[i]
  
          else:
              for i in range(1, tgt_batch_size + 1):
                  if cur_index <= len(queue_tree[i]):
                      par_index = queue_tree[i][cur_index - 1]["parent"]
                      child_index = queue_tree[i][cur_index - 1][
                          "child_index"
                      ]
  
                      dec_state[cur_index][0][1][i - 1, :] = dec_state[
                          par_index
                      ][child_index][1][i - 1, :]
                      dec_state[cur_index][0][2][i - 1, :] = dec_state[
                          par_index
                      ][child_index][2][i - 1, :]
  
                  flag_sibling = False
                  for q_index in range(len(queue_tree[i])):
                      if (
                          (cur_index <= len(queue_tree[i]))
                          and (q_index < cur_index - 1)
                          and (
                              queue_tree[i][q_index]["parent"]
                              == queue_tree[i][cur_index - 1]["parent"]
                          )
                          and (
                              queue_tree[i][q_index]["child_index"]
                              < queue_tree[i][cur_index - 1][
                                  "child_index"
                              ]
                          )
                      ):
                          flag_sibling = True
                          sibling_index = q_index
                  if flag_sibling:
                      sibling_state[i - 1, :] = dec_state[
                          sibling_index
                      ][dec_batch[sibling_index].size(1) - 1][2][
                          i - 1, :
                      ]
  
          parent_h = dec_state[cur_index][0][2]
          pred = None
          for i in range(dec_batch[cur_index].size(1) - 1):
              teacher_force = random.random() < self.teacher_force_ratio
              if teacher_force is not True and i > 0:
                  input_word = pred.argmax(1)
              else:
                  input_word = dec_batch[cur_index][:, i]
              pred, rnn_state_iter, attn_scores = self.decode_step(
                  tgt_batch_size=tgt_batch_size,
                  dec_single_input=input_word,
                  dec_single_state=(
                      dec_state[cur_index][i][1],
                      dec_state[cur_index][i][2],
                  ),
                  memory=enc_outputs,
                  parent_state=parent_h,
                  oov_dict=oov_dict,
                  enc_batch=enc_batch,
              )
  
              (
                  dec_state[cur_index][i + 1][1],
                  dec_state[cur_index][i + 1][2],
              ) = rnn_state_iter
  
              pred = torch.log(pred + 1e-31)
              loss += self.criterion(
                  pred, dec_batch[cur_index][:, i + 1]
              )
          cur_index = cur_index + 1
      loss = loss / tgt_batch_size
      return loss
  
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 2 for calling the StdTreeDecoder obj's underlying member method code with example usage: obj._run_forward_pass(graph_node_embedding, graph_node_mask, rnn_node_embedding, graph_level_embedding, graph_edge_embedding, graph_edge_mask, tgt_tree_batch, enc_batch, oov_dict) and returns: loss