def expand_query(query,k): result = [] generator = dict(load_binary_representations('../people-search-honours/vectors.bin')) for word in query.split(' '): word_vector = generator[word] distances = all_distances(word_vector,generator,{}) neighbours = find_neighbours(distances,k,{}) result.extend(neighbours.keys()) return result
def find_words_neighbours(bin_file, result_file, GloVe): if(GloVe): with open(bin_file,'rb') as glove_file: word_vectors = pickle.load(glove_file) words, vectors = word_vectors else: word_vectors = list(load_binary_representations(bin_file)) words,vectors = zip(*word_vectors) distances, neighbours = find_neighbours(vectors,20) words_neighbours = {} for index in range(len(words)-1): word_neighbours = [] for neighbour in neighbours[index]: word_neighbours.extend([words[neighbour]]) words_neighbours[words[index]] = (word_neighbours, distances[index]) with open(result_file,'wb') as result: pickle.dump(words_neighbours, result)