class_docstr: Object for loading word embeddings and related distances for TextAttack.
  This class has a lot of internal components (e.g. get consine similarity)
  implemented. Consider using this class if you can provide the appropriate
  input data to create the object.
  
  Args:
      emedding_matrix (ndarray): 2-D array of shape N x D where N represents size of vocab and D is the dimension of embedding vectors.
      word2index (Union[dict|object]): dictionary (or a similar object) that maps word to its index with in the embedding matrix.
      index2word (Union[dict|object]): dictionary (or a similar object) that maps index to its word.
      nn_matrix (ndarray): Matrix for precomputed nearest neighbours. It should be a 2-D integer array of shape N x K
          where N represents size of vocab and K is the top-K nearest neighbours. If this is set to `None`, we have to compute nearest neighbours
          on the fly for `nearest_neighbours` method, which is costly.
class_docstr_tok: ["Object","for","loading","word","embeddings","and","related","distances","for","TextAttack",".","This","class","has","a","lot","of","internal","components","(","e.g",".","get","consine","similarity",")","implemented",".","Consider","using","this","class","if","you","can","provide","the","appropriate","input","data","to","create","the","object",".","Args",":","emedding_matrix","(","ndarray",")",":","2-D","array","of","shape","N","x","D","where","N","represents","size","of","vocab","and","D","is","the","dimension","of","embedding","vectors",".","word2index","(","Union","[","dict|object","]",")",":","dictionary","(","or","a","similar","object",")","that","maps","word","to","its","index","with","in","the","embedding","matrix",".","index2word","(","Union","[","dict|object","]",")",":","dictionary","(","or","a","similar","object",")","that","maps","index","to","its","word",".","nn_matrix","(","ndarray",")",":","Matrix","for","precomputed","nearest","neighbours",".","It","should","be","a","2-D","integer","array","of","shape","N","x","K","where","N","represents","size","of","vocab","and","K","is","the","top-K","nearest","neighbours",".","If","this","is","set","to","`","None","`",",","we","have","to","compute","nearest","neighbours","on","the","fly","for","`","nearest_neighbours","`","method",",","which","is","costly","."]
docstr: Gets the embedding vector for word/id
  Args:
      index (Union[str|int]): `index` can either be word or integer representing the id of the word.
  Returns:
      vector (ndarray): 1-D embedding vector. If corresponding vector cannot be found for `index`, returns `None`.
docstr_tok: ["Gets","the","embedding","vector","for","word\/id","Args",":","index","(","Union","[","str|int","]",")",":","`","index","`","can","either","be","word","or","integer","representing","the","id","of","the","word",".","Returns",":","vector","(","ndarray",")",":","1-D","embedding","vector",".","If","corresponding","vector","can","not","be","found","for","`","index","`",",","returns","`","None","`","."]
code: def __getitem__(self, index):
      """Gets the embedding vector for word/id
      Args:
          index (Union[str|int]): `index` can either be word or integer representing the id of the word.
      Returns:
          vector (ndarray): 1-D embedding vector. If corresponding vector cannot be found for `index`, returns `None`.
      """
      if isinstance(index, str):
          try:
              index = self._word2index[index]
          except KeyError:
              return None
      try:
          return self.embedding_matrix[index]
      except IndexError:
          # word embedding ID out of bounds
          return None
  
imports: from abc import ABC, abstractmethod
  from collections import defaultdict
  import os
  import pickle
  import numpy
  import torch
  from textattack.shared import utils
label_desc: Use image node_id 2 for calling the WordEmbedding obj's underlying member method code with example usage: obj.__getitem__(index) and returns: self, None, None