class_docstr: Module for classifying text used in original paper code.
      
class_docstr_tok: ["Module","for","classifying","text","used","in","original","paper","code","."]
docstr: Initialize the layer that embeds tokens according to a provided embedding
  
  :param word_vocab: a mapping of a set of words (keys) to
      indices (values)
  :type word_vocab: dict
docstr_tok: ["Initialize","the","layer","that","embeds","tokens","according","to","a","provided","embedding",":","param","word_vocab",":","a","mapping","of","a","set","of","words","(","keys",")","to","indices","(","values",")",":","type","word_vocab",":","dict"]
code: def init_embedding_layer(self, word_vocab):
      """Initialize the layer that embeds tokens according to a provided embedding
  
      :param word_vocab: a mapping of a set of words (keys) to
          indices (values)
      :type word_vocab: dict
      """
      # get initial vocab embeddings
      vocab_size = len(word_vocab)
      # initialize a numpy embedding matrix
      embeddings = 0.1 * np.random.randn(
          vocab_size, self.input_dim
      ).astype(np.float32)
  
      # replace the <PAD> embedding by all zero
      embeddings[0, :] = np.zeros(self.input_dim, dtype=np.float32)
  
      if self.embedding_path and os.path.isfile(self.embedding_path):
          f = open(self.embedding_path, "r", encoding="utf8")
          counter = 0
          for line in f:
              data = line.strip().split(" ")
              word = data[0].strip()
              embedding = data[1::]
              embedding = list(map(np.float32, embedding))
              if word in word_vocab:
                  embeddings[word_vocab[word], :] = embedding
                  counter += 1
          f.close()
          logging.info("%d words have been switched." % counter)
      else:
          logging.info("embedding is initialized fully randomly.")
  
      # initialize embedding layer
      self.embed_layer = nn.Embedding(vocab_size, self.input_dim)
      self.embed_layer.weight.data = torch.from_numpy(embeddings)
      self.embed_layer.weight.requires_grad = self.fine_tuning
  
imports: import os
  import logging
  import numpy
  import torch
  import torch.nn
  from torch.autograd import Variable
  from tqdm import tqdm
  from interpret_text.experimental.common.utils_introspective_rationale import generate_data
label_desc: Use image node_id 2 for calling the ClassifierModule obj's underlying member method code with example usage: obj.init_embedding_layer(word_vocab) without return types