代码之家  ›  专栏  ›  技术社区  ›  user8566323

Gensim中doc2vec标记中的问题

  •  0
  • user8566323  · 技术社区  · 7 年前

    我正在使用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\uu 001\uu 1”和“recipe\uu 001\uu 2”。

    当我使用 len(model.docvecs.doctag_syn0) 我明白了 9 作为输出。但真正的价值应该是 2

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

    1 回复  |  直到 7 年前
        1
  •  3
  •   Lenka Vraná    7 年前

    尝试更改此行:

    tags = key
    

    tags = [key]