nanom commited on
Commit
37a709b
·
1 Parent(s): ad445e5

Fix bug in getNearestNeighbors() from module_embedding.py

Browse files
Files changed (1) hide show
  1. modules/model_embbeding.py +2 -5
modules/model_embbeding.py CHANGED
@@ -5,7 +5,6 @@ from sklearn.decomposition import PCA
5
  from gensim.models import KeyedVectors
6
  from typing import List
7
  import os
8
- import operator
9
  import pandas as pd
10
 
11
  import numpy as np
@@ -136,14 +135,12 @@ class Embedding:
136
  self,
137
  word: str
138
  ):
139
-
140
  return self.__getValue(word, 'embedding')
141
 
142
  def getPCA(
143
  self,
144
  word: str
145
  ):
146
-
147
  return self.__getValue(word, 'pca')
148
 
149
  def getNearestNeighbors(
@@ -160,8 +157,8 @@ class Embedding:
160
 
161
  elif nn_method == 'sklearn':
162
  word_emb = self.getEmbedding(word).reshape(1,-1)
163
- _, nn_ids = self.neigh.kneighbors(word_emb, n_neighbors)
164
- words = operator.itemgetter(*nn_ids[0])(self.ds['word'].to_list())
165
  else:
166
  words = []
167
  return words
 
5
  from gensim.models import KeyedVectors
6
  from typing import List
7
  import os
 
8
  import pandas as pd
9
 
10
  import numpy as np
 
135
  self,
136
  word: str
137
  ):
 
138
  return self.__getValue(word, 'embedding')
139
 
140
  def getPCA(
141
  self,
142
  word: str
143
  ):
 
144
  return self.__getValue(word, 'pca')
145
 
146
  def getNearestNeighbors(
 
157
 
158
  elif nn_method == 'sklearn':
159
  word_emb = self.getEmbedding(word).reshape(1,-1)
160
+ _, nn_ids = self.neigh.kneighbors(word_emb, n_neighbors + 1) #Fix and Update
161
+ words = [self.ds['word'].to_list()[idx] for idx in nn_ids[0]][1:] #Fix and Update
162
  else:
163
  words = []
164
  return words