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","'",")"]
code: def __init__(
      self,
      word_vocab,
      single_token_item,
      emb_strategy="w2v_bilstm",
      hidden_size=None,
      num_rnn_layers=1,
      fix_word_emb=True,
      fix_bert_emb=True,
      bert_model_name="bert-base-uncased",
      bert_lower_case=True,
      word_dropout=None,
      bert_dropout=None,
      rnn_dropout=None,
  ):
      super(EmbeddingConstruction, self).__init__()
      self.word_dropout = word_dropout
      self.bert_dropout = bert_dropout
      self.rnn_dropout = rnn_dropout
      self.single_token_item = single_token_item
  
      assert emb_strategy in (
          "w2v",
          "w2v_bilstm",
          "w2v_bigru",
          "bert",
          "bert_bilstm",
          "bert_bigru",
          "w2v_bert",
          "w2v_bert_bilstm",
          "w2v_bert_bigru",
      ), "emb_strategy must be one of ('w2v', 'w2v_bilstm', 'w2v_bigru', 'bert', 'bert_bilstm', "
      "'bert_bigru', 'w2v_bert', 'w2v_bert_bilstm', 'w2v_bert_bigru')"
  
      word_emb_type = set()
      if single_token_item:
          node_edge_emb_strategy = None
          if "w2v" in emb_strategy:
              word_emb_type.add("w2v")
  
          if "bert" in emb_strategy:
              word_emb_type.add("seq_bert")
  
          if "bilstm" in emb_strategy:
              seq_info_encode_strategy = "bilstm"
          elif "bigru" in emb_strategy:
              seq_info_encode_strategy = "bigru"
          else:
              seq_info_encode_strategy = "none"
      else:
          seq_info_encode_strategy = "none"
          if "w2v" in emb_strategy:
              word_emb_type.add("w2v")
  
          if "bert" in emb_strategy:
              word_emb_type.add("node_edge_bert")
  
          if "bilstm" in emb_strategy:
              node_edge_emb_strategy = "bilstm"
          elif "bigru" in emb_strategy:
              node_edge_emb_strategy = "bigru"
          else:
              node_edge_emb_strategy = "mean"
  
      word_emb_size = 0
      self.word_emb_layers = nn.ModuleDict()
      if "w2v" in word_emb_type:
          self.word_emb_layers["w2v"] = WordEmbedding(
              word_vocab.embeddings.shape[0],
              word_vocab.embeddings.shape[1],
              pretrained_word_emb=word_vocab.embeddings,
              fix_emb=fix_word_emb,
          )
          word_emb_size += word_vocab.embeddings.shape[1]
  
      if "node_edge_bert" in word_emb_type:
          self.word_emb_layers["node_edge_bert"] = BertEmbedding(
              name=bert_model_name,
              fix_emb=fix_bert_emb,
              lower_case=bert_lower_case,
          )
          word_emb_size += self.word_emb_layers[
              "node_edge_bert"
          ].bert_model.config.hidden_size
  
      if "seq_bert" in word_emb_type:
          self.word_emb_layers["seq_bert"] = BertEmbedding(
              name=bert_model_name,
              fix_emb=fix_bert_emb,
              lower_case=bert_lower_case,
          )
  
      if node_edge_emb_strategy in ("bilstm", "bigru"):
          self.node_edge_emb_layer = RNNEmbedding(
              word_emb_size,
              hidden_size,
              bidirectional=True,
              num_layers=num_rnn_layers,
              rnn_type="lstm"
              if node_edge_emb_strategy == "bilstm"
              else "gru",
              dropout=rnn_dropout,
          )
          rnn_input_size = hidden_size
      elif node_edge_emb_strategy == "mean":
          self.node_edge_emb_layer = MeanEmbedding()
          rnn_input_size = word_emb_size
      else:
          rnn_input_size = word_emb_size
  
      if "seq_bert" in word_emb_type:
          rnn_input_size += self.word_emb_layers[
              "seq_bert"
          ].bert_model.config.hidden_size
  
      if seq_info_encode_strategy in ("bilstm", "bigru"):
          self.output_size = hidden_size
          self.seq_info_encode_layer = RNNEmbedding(
              rnn_input_size,
              hidden_size,
              bidirectional=True,
              num_layers=num_rnn_layers,
              rnn_type="lstm"
              if seq_info_encode_strategy == "bilstm"
              else "gru",
              dropout=rnn_dropout,
          )
  
      else:
          self.output_size = rnn_input_size
          self.seq_info_encode_layer = None
  
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 1 to create a new EmbeddingConstruction object from inherited base classes: EmbeddingConstructionBase with example: obj = EmbeddingConstruction(word_vocab, single_token_item, emb_strategy, hidden_size, num_rnn_layers, fix_word_emb, fix_bert_emb, bert_model_name, bert_lower_case, word_dropout, bert_dropout, rnn_dropout)