class_docstr:     The standard rnn for sequence decoder.
  Parameters
  ----------
  max_decoder_step: int
      The maximal decoding step.
  input_size: int
      The dimension for standard rnn decoder's input.
  hidden_size: int
      The dimension for standard rnn decoder's hidden representation during calculation.
  word_emb: torch.nn.Embedding
      The target's embedding matrix.
  vocab: Any
      The target's vocabulary
  rnn_type: str, option=["lstm", "gru"], default="lstm"
      The rnn's type. We support ``lstm`` and ``gru`` here.
  use_attention: bool, default=True
      Whether use attention during decoding.
  attention_type: str, option=["uniform", "sep_diff_encoder_type", sep_diff_node_type], default="uniform" # noqa
      The attention strategy choice.
      "``uniform``": uniform attention. We will attend on the nodes uniformly.
      "``sep_diff_encoder_type``": separate attention.
          We will attend on graph encoder and rnn encoder's results separately.
      "``sep_diff_node_type``": separate attention.
          We will attend on different node type separately.
  
  attention_function: str, option=["general", "mlp"], default="mlp"
      Different attention function.
  node_type_num: int, default=None
      When we choose "``sep_diff_node_type``", we must set this parameter.
      This parameter indicate the the amount of node type.
  fuse_strategy: str, option=["average", "concatenate"], default=average
      The strategy to fuse attention results generated by separate attention.
      "``average``": We will take an average on all results.
      "``concatenate``": We will concatenate all results to one.
  use_copy: bool, default=False
      Whether use ``copy`` mechanism. See pointer network. Note that you must use attention first.
  use_coverage: bool, default=False
      Whether use ``coverage`` mechanism. Note that you must use attention first.
  coverage_strategy: str, option=["sum", "max"], default="sum"
      The coverage strategy when calculating the coverage vector.
  tgt_emb_as_output_layer: bool, default=False
      When this option is set ``True``, the output projection layer(It is used to project RNN encoded # noqa
      representation to target sequence)'s weight will be shared with the target vocabulary's embedding. # noqa
  dropout: float, default=0.3
class_docstr_tok: ["The","standard","rnn","for","sequence","decoder",".","Parameters","--","--","--","--","--","max_decoder_step",":","int","The","maximal","decoding","step",".","input_size",":","int","The","dimension","for","standard","rnn","decoder","'s","input",".","hidden_size",":","int","The","dimension","for","standard","rnn","decoder","'s","hidden","representation","during","calculation",".","word_emb",":","torch.nn.Embedding","The","target","'s","embedding","matrix",".","vocab",":","Any","The","target","'s","vocabulary","rnn_type",":","str",",","option=","[","``","lstm","''",",","``","gru","''","]",",","default=","''","lstm","''","The","rnn","'s","type",".","We","support","``","lstm","``","and","``","gru","``","here",".","use_attention",":","bool",",","default=True","Whether","use","attention","during","decoding",".","attention_type",":","str",",","option=","[","``","uniform","''",",","``","sep_diff_encoder_type","''",",","sep_diff_node_type","]",",","default=","''","uniform","''","#","noqa","The","attention","strategy","choice",".","``","``","uniform","``","``",":","uniform","attention",".","We","will","attend","on","the","nodes","uniformly",".","``","``","sep_diff_encoder_type","``","``",":","separate","attention",".","We","will","attend","on","graph","encoder","and","rnn","encoder","'s","results","separately",".","``","``","sep_diff_node_type","``","``",":","separate","attention",".","We","will","attend","on","different","node","type","separately",".","attention_function",":","str",",","option=","[","``","general","''",",","``","mlp","''","]",",","default=","''","mlp","''","Different","attention","function",".","node_type_num",":","int",",","default=None","When","we","choose","``","``","sep_diff_node_type","``","``",",","we","must","set","this","parameter",".","This","parameter","indicate","the","the","amount","of","node","type",".","fuse_strategy",":","str",",","option=","[","``","average","''",",","``","concatenate","''","]",",","default=average","The","strategy","to","fuse","attention","results","generated","by","separate","attention",".","``","``","average","``","``",":","We","will","take","an","average","on","all","results",".","``","``","concatenate","``","``",":","We","will","concatenate","all","results","to","one",".","use_copy",":","bool",",","default=False","Whether","use","``","copy","``","mechanism",".","See","pointer","network",".","Note","that","you","must","use","attention","first",".","use_coverage",":","bool",",","default=False","Whether","use","``","coverage","``","mechanism",".","Note","that","you","must","use","attention","first",".","coverage_strategy",":","str",",","option=","[","``","sum","''",",","``","max","''","]",",","default=","''","sum","''","The","coverage","strategy","when","calculating","the","coverage","vector",".","tgt_emb_as_output_layer",":","bool",",","default=False","When","this","option","is","set","``","True","``",",","the","output","projection","layer","(","It","is","used","to","project","RNN","encoded","#","noqa","representation","to","target","sequence",")","'s","weight","will","be","shared","with","the","target","vocabulary","'s","embedding",".","#","noqa","dropout",":","float",",","default=0.3"]
docstr:     The forward function for RNN.
  Parameters
  ----------
  graph_node_embedding: torch.Tensor
      shape=[B, N, D]
  graph_node_mask: torch.Tensor
      shape=[B, N]
      -1 indicating dummy node. 0-``node_type_num`` are valid node type.
  rnn_node_embedding: torch.Tensor
      shape=[B, N, D]
  graph_level_embedding: torch.Tensor
      shape=[B, D]
  graph_edge_embedding: torch.Tensor
      shape=[B, E, D]
      Not implemented yet.
  graph_edge_mask: torch.Tensor
      shape=[B, E]
      Not implemented yet.
  tgt_seq: torch.Tensor
      shape=[B, T]
      The target sequence's index.
  src_seq: torch.Tensor
      shape=[B, S]
      The source sequence's index. It is used for ``use_copy``.
      Note that it can be encoded by target word embedding.
  oov_dict: Vocab
  teacher_forcing_rate: float, default=1.0
      The teacher forcing rate.
  
  Returns
  -------
  logits: torch.Tensor
      shape=[B, tgt_len, vocab_size]
      The probability for predicted target sequence. It is processed by softmax function.
  enc_attn_weights_average: torch.Tensor
      It is used for calculating coverage loss.
      The averaged attention scores.
  coverage_vectors: torch.Tensor
      It is used for calculating coverage loss.
      The coverage vector.
docstr_tok: ["The","forward","function","for","RNN",".","Parameters","--","--","--","--","--","graph_node_embedding",":","torch.Tensor","shape=","[","B",",","N",",","D","]","graph_node_mask",":","torch.Tensor","shape=","[","B",",","N","]","-1","indicating","dummy","node",".","0-","``","node_type_num","``","are","valid","node","type",".","rnn_node_embedding",":","torch.Tensor","shape=","[","B",",","N",",","D","]","graph_level_embedding",":","torch.Tensor","shape=","[","B",",","D","]","graph_edge_embedding",":","torch.Tensor","shape=","[","B",",","E",",","D","]","Not","implemented","yet",".","graph_edge_mask",":","torch.Tensor","shape=","[","B",",","E","]","Not","implemented","yet",".","tgt_seq",":","torch.Tensor","shape=","[","B",",","T","]","The","target","sequence","'s","index",".","src_seq",":","torch.Tensor","shape=","[","B",",","S","]","The","source","sequence","'s","index",".","It","is","used","for","``","use_copy","``",".","Note","that","it","can","be","encoded","by","target","word","embedding",".","oov_dict",":","Vocab","teacher_forcing_rate",":","float",",","default=1.0","The","teacher","forcing","rate",".","Returns","--","--","--","-","logits",":","torch.Tensor","shape=","[","B",",","tgt_len",",","vocab_size","]","The","probability","for","predicted","target","sequence",".","It","is","processed","by","softmax","function",".","enc_attn_weights_average",":","torch.Tensor","It","is","used","for","calculating","coverage","loss",".","The","averaged","attention","scores",".","coverage_vectors",":","torch.Tensor","It","is","used","for","calculating","coverage","loss",".","The","coverage","vector","."]
code: def _run_forward_pass(
      self,
      graph_node_embedding,
      graph_node_mask=None,
      rnn_node_embedding=None,
      graph_level_embedding=None,
      graph_edge_embedding=None,
      graph_edge_mask=None,
      tgt_seq=None,
      src_seq=None,
      oov_dict=None,
      teacher_forcing_rate=1.0,
  ):
      """
          The forward function for RNN.
      Parameters
      ----------
      graph_node_embedding: torch.Tensor
          shape=[B, N, D]
      graph_node_mask: torch.Tensor
          shape=[B, N]
          -1 indicating dummy node. 0-``node_type_num`` are valid node type.
      rnn_node_embedding: torch.Tensor
          shape=[B, N, D]
      graph_level_embedding: torch.Tensor
          shape=[B, D]
      graph_edge_embedding: torch.Tensor
          shape=[B, E, D]
          Not implemented yet.
      graph_edge_mask: torch.Tensor
          shape=[B, E]
          Not implemented yet.
      tgt_seq: torch.Tensor
          shape=[B, T]
          The target sequence's index.
      src_seq: torch.Tensor
          shape=[B, S]
          The source sequence's index. It is used for ``use_copy``.
          Note that it can be encoded by target word embedding.
      oov_dict: Vocab
      teacher_forcing_rate: float, default=1.0
          The teacher forcing rate.
  
      Returns
      -------
      logits: torch.Tensor
          shape=[B, tgt_len, vocab_size]
          The probability for predicted target sequence. It is processed by softmax function.
      enc_attn_weights_average: torch.Tensor
          It is used for calculating coverage loss.
          The averaged attention scores.
      coverage_vectors: torch.Tensor
          It is used for calculating coverage loss.
          The coverage vector.
      """
      target_len = self.max_decoder_step
      if tgt_seq is not None:
          target_len = tgt_seq.shape[1]
  
      batch_size = graph_node_embedding.shape[0]
      decoder_input = torch.tensor([self.vocab.SOS] * batch_size).to(
          graph_node_embedding.device
      )
  
      decoder_state = self.get_decoder_init_state(
          rnn_type=self.rnn_type,
          batch_size=batch_size,
          content=graph_level_embedding,
      )
  
      input_feed = torch.zeros(batch_size, self.input_feed_size).to(
          graph_node_embedding.device
      )
  
      outputs = []
      enc_attn_weights_average = []
      coverage_vectors = []
  
      for i in range(target_len):
          (
              decoder_output,
              input_feed,
              decoder_state,
              dec_attn_scores,
              coverage_vec,
          ) = self.decode_step(
              decoder_input=decoder_input,
              input_feed=input_feed,
              rnn_state=decoder_state,
              dec_input_mask=graph_node_mask,
              encoder_out=graph_node_embedding,
              rnn_emb=rnn_node_embedding,
              enc_attn_weights_average=enc_attn_weights_average,
              src_seq=src_seq,
              oov_dict=oov_dict,
          )
          if self.use_coverage:
              enc_attn_weights_average.append(
                  dec_attn_scores.unsqueeze(0)
              )
              coverage_vectors.append(coverage_vec)
  
          outputs.append(decoder_output.unsqueeze(1))
  
          # teacher_forcing
          if (
              tgt_seq is not None
              and random.random() < teacher_forcing_rate
          ):
              decoder_input = tgt_seq[:, i]
          else:
              # sampling
              # TODO: now argmax sampling
              decoder_input = decoder_output.squeeze(1).argmax(dim=-1)
          decoder_input = self._filter_oov(decoder_input)
      ret = torch.cat(outputs, dim=1)
  
      return ret, enc_attn_weights_average, coverage_vectors
  
file_path: graph4nlp/graph4nlp/pytorch/modules/prediction/generation/StdRNNDecoder.py
imports: import random
  from functools import reduce
  import torch
  import torch.nn
  from graph4nlp.pytorch.modules.prediction.generation.attention import Attention
  from graph4nlp.pytorch.modules.prediction.generation.base import RNNDecoderBase
  from graph4nlp.pytorch.modules.utils.vocab_utils import Vocab
label_desc: Use image node_id 4 for calling the StdRNNDecoder 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_seq, src_seq, oov_dict, teacher_forcing_rate) and returns: ret,  enc_attn_weights_average,  coverage_vectors