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: Convert between word to id (i.e. index of word in embedding matrix)
  Args:
      word (str)
  Returns:
      index (int)
docstr_tok: ["Convert","between","word","to","id","(","i.e",".","index","of","word","in","embedding","matrix",")","Args",":","word","(","str",")","Returns",":","index","(","int",")"]
code: def word2index(self, word):
      """
      Convert between word to id (i.e. index of word in embedding matrix)
      Args:
          word (str)
      Returns:
          index (int)
      """
      return self._word2index[word]
  
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 3 for calling the WordEmbedding obj's underlying member method code with example usage: obj.word2index(word) and returns: self