我尝试使用预先训练的单词嵌入来考虑短语。流行的预训练嵌入,如GoogleNews-vectors-negative300.bin.gz
对短语和unigram都有单独的嵌入,例如,New_York
和两个unigramNew
和{
Gensim提供了一个很好的Phrase模型,在给定的文本序列中,它可以学习紧凑的短语,例如,New_York
而不是两个单字New
和{Phrase
与预先训练的嵌入一起使用,而无需估计其他地方的计数统计信息?在
Phrase
与预先训练的嵌入一起使用,而无需估计其他地方的计数统计信息?在这是丑陋的代码。在
from ntlk import word_tokenize
last_added = False
sentence = 'I love New York.'
tokens = ["<s>"]+ word_tokenize(sentence) +"<\s>"]
vectors = []
for index, token in enumerate(tokens):
if last_added:
last_added=False
continue
if "%s_%s"%(tokens[index-1], token) in model:
vectors.append("%s_%s"%(tokens[index-1], token))
last_added = True
else:
vectors.append(tokens[index-1])
lase_added = False
目前没有回答
相关问题 更多 >
编程相关推荐