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: Returns a prebuilt counter-fitted GLOVE word embedding proposed by
  "Counter-fitting Word Vectors to Linguistic Constraints" (Mrkšić et
  al., 2016)
docstr_tok: ["Returns","a","prebuilt","counter-fitted","GLOVE","word","embedding","proposed","by","''","Counter-fitting","Word","Vectors","to","Linguistic","Constraints","''","(","Mrk\u0161i\u0107","et","al.",",","2016",")"]
code: def counterfitted_GLOVE_embedding():
      """Returns a prebuilt counter-fitted GLOVE word embedding proposed by
      "Counter-fitting Word Vectors to Linguistic Constraints" (Mrkšić et
      al., 2016)"""
      if (
          "textattack_counterfitted_GLOVE_embedding"
          in utils.GLOBAL_OBJECTS
          and isinstance(
              utils.GLOBAL_OBJECTS[
                  "textattack_counterfitted_GLOVE_embedding"
              ],
              WordEmbedding,
          )
      ):
          # avoid recreating same embedding (same memory) and instead share across different components
          return utils.GLOBAL_OBJECTS[
              "textattack_counterfitted_GLOVE_embedding"
          ]
  
      word_embeddings_folder = "paragramcf"
      word_embeddings_file = "paragram.npy"
      word_list_file = "wordlist.pickle"
      mse_dist_file = "mse_dist.p"
      cos_sim_file = "cos_sim.p"
      nn_matrix_file = "nn.npy"
  
      # Download embeddings if they're not cached.
      word_embeddings_folder = os.path.join(
          WordEmbedding.PATH, word_embeddings_folder
      ).replace("\\", "/")
      word_embeddings_folder = utils.download_from_s3(
          word_embeddings_folder
      )
      # Concatenate folder names to create full path to files.
      word_embeddings_file = os.path.join(
          word_embeddings_folder, word_embeddings_file
      )
      word_list_file = os.path.join(
          word_embeddings_folder, word_list_file
      )
      mse_dist_file = os.path.join(
          word_embeddings_folder, mse_dist_file
      )
      cos_sim_file = os.path.join(word_embeddings_folder, cos_sim_file)
      nn_matrix_file = os.path.join(
          word_embeddings_folder, nn_matrix_file
      )
  
      # loading the files
      embedding_matrix = np.load(word_embeddings_file)
      word2index = np.load(word_list_file, allow_pickle=True)
      index2word = {}
      for word, index in word2index.items():
          index2word[index] = word
      nn_matrix = np.load(nn_matrix_file)
  
      embedding = WordEmbedding(
          embedding_matrix, word2index, index2word, nn_matrix
      )
  
      with open(mse_dist_file, "rb") as f:
          mse_dist_mat = pickle.load(f)
      with open(cos_sim_file, "rb") as f:
          cos_sim_mat = pickle.load(f)
  
      embedding._mse_dist_mat = mse_dist_mat
      embedding._cos_sim_mat = cos_sim_mat
  
      utils.GLOBAL_OBJECTS[
          "textattack_counterfitted_GLOVE_embedding"
      ] = embedding
  
      return embedding
  
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 8 for calling the WordEmbedding obj's underlying member method code with example usage: obj.counterfitted_GLOVE_embedding() and returns: embedding, utils