def sanity_check(test_emb, train_emb, num_test):
'''
Sanity check on the cosine similarity calculations
Finds the closest vector in the space by brute force
'''
correct_list = []
for i in xrange(num_test):
smallest_norm = np.infty
index = 0
for j in xrange(len(train_emb)):
norm = np.linalg.norm(emb - test_emb[i])
if norm < smallest_norm:
smallest_norm = norm
index = j
correct_list.append(index)
# Pad the list to make it the same length as test_emb
for i in xrange(len(test_emb) - num_test):
correct_list.append(-1)
return correct_list
评论列表
文章目录