tfidf_retrieval.py 文件源码

python
阅读 43 收藏 0 点赞 0 评论 0

项目:ADEM 作者: mike-n-7 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号