【问题标题】:Issues in doc2vec tags in GensimGensim 中 doc2vec 标签中的问题
【发布时间】: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,因为我的测试字典中只有两个食谱。

请告诉我,为什么会这样?

【问题讨论】:

    标签: python gensim doc2vec


    【解决方案1】:

    尝试改变这一行:

    tags = key
    

    tags = [key]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-12
      • 2016-06-07
      • 2018-07-21
      • 2018-12-17
      • 1970-01-01
      相关资源
      最近更新 更多