def process_questions(C, all_words, n):
scores = dist_function[0](C[:, all_words], W[all_words, :], W2)
worst = -dist_function[1]*numpy.Inf
for i in range(C.shape[0]):
scores[i, C[i, :].nonzero()[1]] = worst
if dist_function[1] > 0:
hits = scores.argpartition(-n, axis=1)[:, -n:]
answers = [sorted(hits[i], key=lambda hit: scores[i, hit], reverse=True) for i in range(len(hits))]
else:
hits = scores.argpartition(n, axis=1)[:, :n]
answers = [sorted(hits[i], key=lambda hit: scores[i, hit], reverse=False) for i in range(len(hits))]
if args.log_level > 1:
small_scores = [scores[i, answers[i]] for i in xrange(hits.shape[0])]
else:
small_scores = None
return answers, small_scores
评论列表
文章目录