class_docstr: A gated graph neural network configured as an encoder.
     Based on github.com/JamesChuanggg/ggnn.pytorch.git,
     which is based on the paper "Gated Graph Sequence Neural Networks"
     by Y. Li, D. Tarlow, M. Brockschmidt, and R. Zemel.
  
  Args:
     rnn_type (str):
        style of recurrent unit to use, one of [LSTM]
     src_ggnn_size (int) : Size of token-to-node embedding input
     src_word_vec_size (int) : Size of token-to-node embedding output
     state_dim (int) : Number of state dimensions in nodes
     n_edge_types (int) : Number of edge types
     bidir_edges (bool): True if reverse edges should be autocreated
     n_node (int) : Max nodes in graph
     bridge_extra_node (bool): True indicates only 1st extra node
        (after token listing) should be used for decoder init.
     n_steps (int): Steps to advance graph encoder for stabilization
     src_vocab (int): Path to source vocabulary.(The ggnn uses src_vocab
          during training because the graph is built using edge information
          which requires parsing the input sequence.)
class_docstr_tok: ["A","gated","graph","neural","network","configured","as","an","encoder",".","Based","on","github.com\/JamesChuanggg\/ggnn.pytorch.git",",","which","is","based","on","the","paper","``","Gated","Graph","Sequence","Neural","Networks","''","by","Y.","Li",",","D.","Tarlow",",","M.","Brockschmidt",",","and","R.","Zemel",".","Args",":","rnn_type","(","str",")",":","style","of","recurrent","unit","to","use",",","one","of","[","LSTM","]","src_ggnn_size","(","int",")",":","Size","of","token-to-node","embedding","input","src_word_vec_size","(","int",")",":","Size","of","token-to-node","embedding","output","state_dim","(","int",")",":","Number","of","state","dimensions","in","nodes","n_edge_types","(","int",")",":","Number","of","edge","types","bidir_edges","(","bool",")",":","True","if","reverse","edges","should","be","autocreated","n_node","(","int",")",":","Max","nodes","in","graph","bridge_extra_node","(","bool",")",":","True","indicates","only","1st","extra","node","(","after","token","listing",")","should","be","used","for","decoder","init",".","n_steps","(","int",")",":","Steps","to","advance","graph","encoder","for","stabilization","src_vocab","(","int",")",":","Path","to","source","vocabulary",".","(","The","ggnn","uses","src_vocab","during","training","because","the","graph","is","built","using","edge","information","which","requires","parsing","the","input","sequence",".",")"]
code: def __init__(
      self,
      rnn_type,
      src_word_vec_size,
      src_ggnn_size,
      state_dim,
      bidir_edges,
      n_edge_types,
      n_node,
      bridge_extra_node,
      n_steps,
      src_vocab,
  ):
      super(GGNNEncoder, self).__init__()
  
      self.src_word_vec_size = src_word_vec_size
      self.src_ggnn_size = src_ggnn_size
      self.state_dim = state_dim
      self.n_edge_types = n_edge_types
      self.n_node = n_node
      self.n_steps = n_steps
      self.bidir_edges = bidir_edges
      self.bridge_extra_node = bridge_extra_node
  
      for i in range(self.n_edge_types):
          # incoming and outgoing edge embedding
          in_fc = nn.Linear(self.state_dim, self.state_dim)
          out_fc = nn.Linear(self.state_dim, self.state_dim)
          self.add_module("in_{}".format(i), in_fc)
          self.add_module("out_{}".format(i), out_fc)
  
      self.in_fcs = GGNNAttrProxy(self, "in_")
      self.out_fcs = GGNNAttrProxy(self, "out_")
  
      # Find vocab data for tree builting
      f = open(src_vocab, "r")
      idx = 0
      self.COMMA = -1
      self.DELIMITER = -1
      self.idx2num = []
      found_n_minus_one = False
      for ln in f:
          ln = ln.strip("\n")
          ln = ln.split("\t")[0]
          if idx == 0 and ln != "<unk>":
              idx += 1
              self.idx2num.append(-1)
          if idx == 1 and ln != "<blank>":
              idx += 1
              self.idx2num.append(-1)
          if ln == ",":
              self.COMMA = idx
          if ln == "<EOT>":
              self.DELIMITER = idx
          if ln.isdigit():
              self.idx2num.append(int(ln))
              if int(ln) == n_node - 1:
                  found_n_minus_one = True
          else:
              self.idx2num.append(-1)
          idx += 1
  
      assert (
          self.COMMA >= 0
      ), "GGNN src_vocab must include ',' character"
      assert (
          self.DELIMITER >= 0
      ), "GGNN src_vocab must include <EOT> token"
      assert (
          found_n_minus_one
      ), "GGNN src_vocab must include node numbers for edge connections"
  
      # Propogation Model
      self.propogator = GGNNPropogator(
          self.state_dim, self.n_node, self.n_edge_types
      )
  
      self._initialization()
  
      # Initialize the bridge layer
      self._initialize_bridge(rnn_type, self.state_dim, 1)
  
      # Token embedding
      if src_ggnn_size > 0:
          self.embed = nn.Sequential(
              nn.Linear(src_ggnn_size, src_word_vec_size),
              nn.LeakyReLU(),
          )
          assert (
              self.src_ggnn_size >= self.DELIMITER
          ), "Embedding input must be larger than vocabulary"
          assert (
              self.src_word_vec_size < self.state_dim
          ), "Embedding size must be smaller than state_dim"
      else:
          assert (
              self.DELIMITER < self.state_dim
          ), "Vocabulary too large, consider -src_ggnn_size"
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from onmt.encoders.encoder import EncoderBase
label_desc: Use image node_id 1 to create a new GGNNEncoder object from inherited base classes: EncoderBase with example: obj = GGNNEncoder(rnn_type, src_word_vec_size, src_ggnn_size, state_dim, bidir_edges, n_edge_types, n_node, bridge_extra_node, n_steps, src_vocab)