class_docstr: A layer of a model that replaces word IDs with their embeddings.
  
  This is a useful abstraction for any nn.module which wants to take
  word IDs (a sequence of text) as input layer but actually manipulate
  words' embeddings.
  
  Requires some pre-trained embedding with associated word IDs.
code: def __init__(
      self,
      n_d=100,
      embedding_matrix=None,
      word_list=None,
      oov="<oov>",
      pad="<pad>",
      normalize=True,
  ):
      super(EmbeddingLayer, self).__init__()
      word2id = {}
      if embedding_matrix is not None:
          for word in word_list:
              assert (
                  word not in word2id
              ), "Duplicate words in pre-trained embeddings"
              word2id[word] = len(word2id)
  
          logger.debug(
              f"{len(word2id)} pre-trained word embeddings loaded.\n"
          )
  
          n_d = len(embedding_matrix[0])
  
      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)
  
      weight = self.embedding.weight
      weight.data[: len(word_list)].copy_(
          torch.from_numpy(embedding_matrix)
      )
      logger.debug(f"EmbeddingLayer shape: {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))
  
file_path: TextAttack/textattack/models/helpers/glove_embedding_layer.py
imports: import os
  import numpy
  import torch
  from torch import nn
  from textattack.shared import logger, utils
label_desc: Use image node_id 1 to create a new EmbeddingLayer object from inherited base classes: nn with example: obj = EmbeddingLayer(n_d, embedding_matrix, word_list, oov, pad, normalize)