class_docstr: Initial graph embedding construction class.
  
  Parameters
  ----------
  word_vocab : Vocab
      The word vocabulary.
  single_token_item : bool
      Specify whether the item (i.e., node or edge) contains single token or multiple tokens.
  emb_strategy : str
      Specify the embedding construction strategy including the following options:
          - 'w2v': use word2vec embeddings.
          - 'w2v_bilstm': use word2vec embeddings, and apply BiLSTM encoders.
          - 'w2v_bigru': use word2vec embeddings, and apply BiGRU encoders.
          - 'bert': use BERT embeddings.
          - 'bert_bilstm': use BERT embeddings, and apply BiLSTM encoders.
          - 'bert_bigru': use BERT embeddings, and apply BiGRU encoders.
          - 'w2v_bert': use word2vec and BERT embeddings.
          - 'w2v_bert_bilstm': use word2vec and BERT embeddings, and apply BiLSTM encoders.
          - 'w2v_bert_bigru': use word2vec and BERT embeddings, and apply BiGRU encoders.
      Note that if 'w2v' is not applied, `pretrained_word_emb_name` specified in Dataset APIs
      will be superseded.
  hidden_size : int, optional
      The hidden size of RNN layer, default: ``None``.
  num_rnn_layers : int, optional
      The number of RNN layers, default: ``1``.
  fix_word_emb : boolean, optional
      Specify whether to fix pretrained word embeddings, default: ``True``.
  fix_bert_emb : boolean, optional
      Specify whether to fix pretrained BERT embeddings, default: ``True``.
  bert_model_name : str, optional
      Specify the BERT model name, default: ``'bert-base-uncased'``.
  bert_lower_case : bool, optional
      Specify whether to lower case the input text for BERT embeddings, default: ``True``.
  word_dropout : float, optional
      Dropout ratio for word embedding, default: ``None``.
  rnn_dropout : float, optional
      Dropout ratio for RNN embedding, default: ``None``.
  
  Note
  ----------
      word_emb_type : str or list of str
          Specify pretrained word embedding types including "w2v", "node_edge_bert",
          or "seq_bert".
      node_edge_emb_strategy : str
          Specify node/edge embedding strategies including "mean", "bilstm" and "bigru".
      seq_info_encode_strategy : str
          Specify strategies of encoding sequential information in raw text
          data including "none", "bilstm" and "bigru". You might
          want to do this in some situations, e.g., when all the nodes are single
          tokens extracted from the raw text.
  
      1) single-token node (i.e., single_token_item=`True`):
          a) 'w2v', 'bert', 'w2v_bert'
          b) node_edge_emb_strategy: 'mean'
          c) seq_info_encode_strategy: 'none', 'bilstm', 'bigru'
          emb_strategy: 'w2v', 'w2v_bilstm', 'w2v_bigru',
          'bert', 'bert_bilstm', 'bert_bigru',
          'w2v_bert', 'w2v_bert_bilstm', 'w2v_bert_bigru'
  
      2) multi-token node (i.e., single_token_item=`False`):
          a) 'w2v', 'bert', 'w2v_bert'
          b) node_edge_emb_strategy: 'mean', 'bilstm', 'bigru'
          c) seq_info_encode_strategy: 'none'
          emb_strategy: ('w2v', 'w2v_bilstm', 'w2v_bigru',
          'bert', 'bert_bilstm', 'bert_bigru',
          'w2v_bert', 'w2v_bert_bilstm', 'w2v_bert_bigru')
class_docstr_tok: ["Initial","graph","embedding","construction","class",".","Parameters","--","--","--","--","--","word_vocab",":","Vocab","The","word","vocabulary",".","single_token_item",":","bool","Specify","whether","the","item","(","i.e.",",","node","or","edge",")","contains","single","token","or","multiple","tokens",".","emb_strategy",":","str","Specify","the","embedding","construction","strategy","including","the","following","options",":","-","'w2v","'",":","use","word2vec","embeddings",".","-","'w2v_bilstm","'",":","use","word2vec","embeddings",",","and","apply","BiLSTM","encoders",".","-","'w2v_bigru","'",":","use","word2vec","embeddings",",","and","apply","BiGRU","encoders",".","-","'bert","'",":","use","BERT","embeddings",".","-","'bert_bilstm","'",":","use","BERT","embeddings",",","and","apply","BiLSTM","encoders",".","-","'bert_bigru","'",":","use","BERT","embeddings",",","and","apply","BiGRU","encoders",".","-","'w2v_bert","'",":","use","word2vec","and","BERT","embeddings",".","-","'w2v_bert_bilstm","'",":","use","word2vec","and","BERT","embeddings",",","and","apply","BiLSTM","encoders",".","-","'w2v_bert_bigru","'",":","use","word2vec","and","BERT","embeddings",",","and","apply","BiGRU","encoders",".","Note","that","if","'w2v","'","is","not","applied",",","`","pretrained_word_emb_name","`","specified","in","Dataset","APIs","will","be","superseded",".","hidden_size",":","int",",","optional","The","hidden","size","of","RNN","layer",",","default",":","``","None","``",".","num_rnn_layers",":","int",",","optional","The","number","of","RNN","layers",",","default",":","``","1","``",".","fix_word_emb",":","boolean",",","optional","Specify","whether","to","fix","pretrained","word","embeddings",",","default",":","``","True","``",".","fix_bert_emb",":","boolean",",","optional","Specify","whether","to","fix","pretrained","BERT","embeddings",",","default",":","``","True","``",".","bert_model_name",":","str",",","optional","Specify","the","BERT","model","name",",","default",":","``","'bert-base-uncased","'","``",".","bert_lower_case",":","bool",",","optional","Specify","whether","to","lower","case","the","input","text","for","BERT","embeddings",",","default",":","``","True","``",".","word_dropout",":","float",",","optional","Dropout","ratio","for","word","embedding",",","default",":","``","None","``",".","rnn_dropout",":","float",",","optional","Dropout","ratio","for","RNN","embedding",",","default",":","``","None","``",".","Note","--","--","--","--","--","word_emb_type",":","str","or","list","of","str","Specify","pretrained","word","embedding","types","including","``","w2v","''",",","``","node_edge_bert","''",",","or","``","seq_bert","''",".","node_edge_emb_strategy",":","str","Specify","node\/edge","embedding","strategies","including","``","mean","''",",","``","bilstm","''","and","``","bigru","''",".","seq_info_encode_strategy",":","str","Specify","strategies","of","encoding","sequential","information","in","raw","text","data","including","``","none","''",",","``","bilstm","''","and","``","bigru","''",".","You","might","want","to","do","this","in","some","situations",",","e.g.",",","when","all","the","nodes","are","single","tokens","extracted","from","the","raw","text",".","1",")","single-token","node","(","i.e.",",","single_token_item=","`","True","`",")",":","a",")","'w2v","'",",","'bert","'",",","'w2v_bert'","b",")","node_edge_emb_strategy",":","'mean'","c",")","seq_info_encode_strategy",":","'none","'",",","'bilstm","'",",","'bigru'","emb_strategy",":","'w2v","'",",","'w2v_bilstm","'",",","'w2v_bigru","'",",","'bert","'",",","'bert_bilstm","'",",","'bert_bigru","'",",","'w2v_bert","'",",","'w2v_bert_bilstm","'",",","'w2v_bert_bigru'","2",")","multi-token","node","(","i.e.",",","single_token_item=","`","False","`",")",":","a",")","'w2v","'",",","'bert","'",",","'w2v_bert'","b",")","node_edge_emb_strategy",":","'mean","'",",","'bilstm","'",",","'bigru'","c",")","seq_info_encode_strategy",":","'none'","emb_strategy",":","(","'w2v","'",",","'w2v_bilstm","'",",","'w2v_bigru","'",",","'bert","'",",","'bert_bilstm","'",",","'bert_bigru","'",",","'w2v_bert","'",",","'w2v_bert_bilstm","'",",","'w2v_bert_bigru","'",")"]
docstr: Compute initial node/edge embeddings.
  
  Parameters
  ----------
  batch_gd : GraphData
      The input graph data.
  
  Returns
  -------
  GraphData
      The output graph data with updated node embeddings.
docstr_tok: ["Compute","initial","node\/edge","embeddings",".","Parameters","--","--","--","--","--","batch_gd",":","GraphData","The","input","graph","data",".","Returns","--","--","--","-","GraphData","The","output","graph","data","with","updated","node","embeddings","."]
code: def forward(self, batch_gd):
      """Compute initial node/edge embeddings.
  
      Parameters
      ----------
      batch_gd : GraphData
          The input graph data.
  
      Returns
      -------
      GraphData
          The output graph data with updated node embeddings.
      """
      feat = []
      if self.single_token_item:  # single-token node graph
          token_ids = batch_gd.batch_node_features["token_id"]
          if "w2v" in self.word_emb_layers:
              word_feat = self.word_emb_layers["w2v"](
                  token_ids
              ).squeeze(-2)
              word_feat = dropout_fn(
                  word_feat,
                  self.word_dropout,
                  shared_axes=[-2],
                  training=self.training,
              )
              feat.append(word_feat)
  
      else:  # multi-token node graph
          token_ids = batch_gd.node_features["token_id"]
          if "w2v" in self.word_emb_layers:
              word_feat = self.word_emb_layers["w2v"](token_ids)
              word_feat = dropout_fn(
                  word_feat,
                  self.word_dropout,
                  shared_axes=[-2],
                  training=self.training,
              )
              feat.append(word_feat)
  
          if "node_edge_bert" in self.word_emb_layers:
              input_data = [
                  batch_gd.node_attributes[i]["token"]
                  .strip()
                  .split(" ")
                  for i in range(batch_gd.get_node_num())
              ]
              node_edge_bert_feat = self.word_emb_layers[
                  "node_edge_bert"
              ](input_data)
              node_edge_bert_feat = dropout_fn(
                  node_edge_bert_feat,
                  self.bert_dropout,
                  shared_axes=[-2],
                  training=self.training,
              )
              feat.append(node_edge_bert_feat)
  
          if len(feat) > 0:
              feat = torch.cat(feat, dim=-1)
              node_token_lens = torch.clamp(
                  (token_ids != Vocab.PAD).sum(-1), min=1
              )
              feat = self.node_edge_emb_layer(feat, node_token_lens)
              if isinstance(feat, (tuple, list)):
                  feat = feat[-1]
  
              feat = batch_gd.split_features(feat)
  
      if (
          self.seq_info_encode_layer is None
          and "seq_bert" not in self.word_emb_layers
      ):
          if isinstance(feat, list):
              feat = torch.cat(feat, -1)
  
          batch_gd.batch_node_features["node_feat"] = feat
  
          return batch_gd
      else:  # single-token node graph
          new_feat = feat
          if "seq_bert" in self.word_emb_layers:
              gd_list = from_batch(batch_gd)
              raw_tokens = [
                  [
                      gd.node_attributes[i]["token"]
                      for i in range(gd.get_node_num())
                  ]
                  for gd in gd_list
              ]
              bert_feat = self.word_emb_layers["seq_bert"](raw_tokens)
              bert_feat = dropout_fn(
                  bert_feat,
                  self.bert_dropout,
                  shared_axes=[-2],
                  training=self.training,
              )
              new_feat.append(bert_feat)
  
          new_feat = torch.cat(new_feat, -1)
          if self.seq_info_encode_layer is None:
              batch_gd.batch_node_features["node_feat"] = new_feat
  
              return batch_gd
  
          rnn_state = self.seq_info_encode_layer(
              new_feat,
              torch.LongTensor(batch_gd._batch_num_nodes).to(
                  batch_gd.device
              ),
          )
          if isinstance(rnn_state, (tuple, list)):
              rnn_state = rnn_state[0]
  
          batch_gd.batch_node_features["node_feat"] = rnn_state
  
          return batch_gd
  
imports: import torch
  from torch import nn
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  from ...data.data import from_batch
  from ..utils.bert_utils import convert_text_to_bert_features, extract_bert_hidden_states
  from ..utils.generic_utils import dropout_fn
  from ..utils.padding_utils import pad_4d_vals
  from ..utils.vocab_utils import Vocab
label_desc: Use image node_id 2 for calling the EmbeddingConstruction obj's underlying member method code with example usage: obj.forward(batch_gd) and returns: batch_gd, batch_gd, batch_gd