code: def __init__(
      self,
      n_d,
      words,
      embs=None,
      fix_emb=True,
      oov="<oov>",
      pad="<pad>",
      normalize=True,
  ):
      super(EmbeddingLayer, self).__init__()
      word2id = {}
      if embs is not None:
          embwords, embvecs = embs
          for word in embwords:
              assert (
                  word not in word2id
              ), "Duplicate words in pre-trained embeddings"
              word2id[word] = len(word2id)
  
          sys.stdout.write(
              "{} pre-trained word embeddings loaded.\n".format(
                  len(word2id)
              )
          )
          if n_d != len(embvecs[0]):
              sys.stdout.write(
                  "[WARNING] n_d ({}) != word vector size ({}). Use {} for embeddings.\n".format(
                      n_d, len(embvecs[0]), len(embvecs[0])
                  )
              )
              n_d = len(embvecs[0])
  
      for w in deep_iter(words):
          if w not in word2id:
              word2id[w] = len(word2id)
  
      if oov not in word2id:
          word2id[oov] = len(word2id)
  
      if pad not in word2id:
          word2id[pad] = len(word2id)
  
      self.word2id = word2id
      self.n_V, self.n_d = len(word2id), n_d
      self.oovid = word2id[oov]
      self.padid = word2id[pad]
      self.embedding = nn.Embedding(self.n_V, n_d)
      self.embedding.weight.data.uniform_(-0.25, 0.25)
  
      if embs is not None:
          weight = self.embedding.weight
          weight.data[: len(embwords)].copy_(torch.from_numpy(embvecs))
          sys.stdout.write(
              "embedding shape: {}\n".format(weight.size())
          )
  
      if normalize:
          weight = self.embedding.weight
          norms = weight.data.norm(2, 1)
          if norms.dim() == 1:
              norms = norms.unsqueeze(1)
          weight.data.div_(norms.expand_as(weight.data))
  
      if fix_emb:
          self.embedding.weight.requires_grad = False
  
file_path: sru/classification/modules.py
imports: import sys
  import torch
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 1 to create a new EmbeddingLayer object from inherited base classes: nn with example: obj = EmbeddingLayer(n_d, words, embs, fix_emb, oov, pad, normalize)