def get_contexts_rank(targets, cooc_mat, target_index):
"""
A dictionary in which each key is a target word and the value is a sorted list of
context columns in descending order
:param targets: the words
:return:
"""
contexts_rank = {}
for target in targets:
index = target_index.get(target, -1)
if index == -1:
contexts_rank[target] = []
row = cooc_mat[index, :]
contexts_rank[target] = sort_by_value_get_col(scipy.sparse.coo_matrix(row.mat)) # tuples of (row, col, value)
return contexts_rank
评论列表
文章目录