我正在使用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
,因为我的测试词典中只有2个食谱。
请让我知道,为什么会这样?
答案 0 :(得分:3)
尝试更改此行:
tags = key
到
tags = [key]