【发布时间】:2017-11-16 14:28:15
【问题描述】:
我正在使用 gensim doc2vec,如下所示。
from gensim.models import doc2vec
from collections import namedtuple
import re
my_d = {'recipe__001__1': 'recipe 1 details should come here',
'recipe__001__2': 'Ingredients of recipe 2 need to be added'}
docs = []
analyzedDocument = namedtuple('AnalyzedDocument', 'words tags')
for key, value in my_d.items():
value = re.sub("[^a-zA-Z]"," ", value)
words = value.lower().split()
tags = key
docs.append(analyzedDocument(words, tags))
model = doc2vec.Doc2Vec(docs, size = 300, window = 10, dm=1, negative=5, hs=0, min_count = 1, workers = 4, iter = 20)
但是,当我检查model.docvecs.offset2doctag 时,我得到['r', 'e', 'c', 'i', 'p', '_', '0', '1', '2'] 作为输出。真正的输出应该是 `'recipe__001__1' 和 'recipe__001__2'。
当我使用len(model.docvecs.doctag_syn0) 时,我得到9 作为输出。但真正的价值应该是2,因为我的测试字典中只有两个食谱。
请告诉我,为什么会这样?
【问题讨论】: