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: Return MSE distance between vector for word `a` and vector for word
  `b`.
  
  Since this is a metric, `get_mse_dist(a,b)` and `get_mse_dist(b,a)` should return the same value.
  Args:
      a (Union[str|int]): Either word or integer presenting the id of the word
      b (Union[str|int]): Either word or integer presenting the id of the word
  Returns:
      distance (float): MSE (L2) distance
docstr_tok: ["Return","MSE","distance","between","vector","for","word","`","a","`","and","vector","for","word","`","b","`",".","Since","this","is","a","metric",",","`","get_mse_dist","(","a",",","b",")","`","and","`","get_mse_dist","(","b",",","a",")","`","should","return","the","same","value",".","Args",":","a","(","Union","[","str|int","]",")",":","Either","word","or","integer","presenting","the","id","of","the","word","b","(","Union","[","str|int","]",")",":","Either","word","or","integer","presenting","the","id","of","the","word","Returns",":","distance","(","float",")",":","MSE","(","L2",")","distance"]
code: def get_mse_dist(self, a, b):
      """Return MSE distance between vector for word `a` and vector for word
      `b`.
  
      Since this is a metric, `get_mse_dist(a,b)` and `get_mse_dist(b,a)` should return the same value.
      Args:
          a (Union[str|int]): Either word or integer presenting the id of the word
          b (Union[str|int]): Either word or integer presenting the id of the word
      Returns:
          distance (float): MSE (L2) distance
      """
      if isinstance(a, str):
          a = self._word2index[a]
      if isinstance(b, str):
          b = self._word2index[b]
      a, b = min(a, b), max(a, b)
      try:
          mse_dist = self._mse_dist_mat[a][b]
      except KeyError:
          e1 = self.embedding_matrix[a]
          e2 = self.embedding_matrix[b]
          e1 = torch.tensor(e1).to(utils.device)
          e2 = torch.tensor(e2).to(utils.device)
          mse_dist = torch.sum((e1 - e2) ** 2).item()
          self._mse_dist_mat[a][b] = mse_dist
  
      return mse_dist
  
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 5 for calling the WordEmbedding obj's underlying member method code with example usage: obj.get_mse_dist(a, b) and returns: mse_dist