本文整理汇总了Python中vocabulary.Vocabulary.get_word_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Vocabulary.get_word_by_id方法的具体用法?Python Vocabulary.get_word_by_id怎么用?Python Vocabulary.get_word_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vocabulary.Vocabulary
的用法示例。
在下文中一共展示了Vocabulary.get_word_by_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: timer
# 需要导入模块: from vocabulary import Vocabulary [as 别名]
# 或者: from vocabulary.Vocabulary import get_word_by_id [as 别名]
matrix_coo=matrix_csr.tocoo()
end = timer()
print(" took",end - start)
start=end
#print(matrix_coo)
cnt_words_processed=vocab.l_frequencies.sum()
#print(matrix_csr)
debug=False
if debug:
f_out=open("bigrams_list","w")
for i in zip(matrix_coo.row,matrix_coo.col):
row=i[0]
col=i[1]
freq=matrix[i]
v=math.log2((freq*cnt_words_processed)/(vocab.l_frequencies[col]*vocab.l_frequencies[col]))
f_out.write("{}\t{}\t{}\t{:0.5f}\n".format(vocab.get_word_by_id(row),vocab.get_word_by_id(col),freq,v))
f_out.close()
#print(matrix_csr.indices.dtype)
data_pmi=np.zeros(matrix_csr.data.shape[0],dtype=np.float32)
ind=0
for i in zip(matrix_coo.row,matrix_coo.col):
row=i[0]
col=i[1]
freq=matrix[i]
v=math.log2((freq*cnt_words_processed)/(vocab.l_frequencies[col]*vocab.l_frequencies[col]))
data_pmi[ind]=v
ind+=1
#f_out=open("bigrams.data.bin","wb")
#f_out.close()
#print(matrix_csr.indices.dtype)