【发布时间】:2017-10-18 09:33:27
【问题描述】:
我是 doc2vec 的新手。我最初试图理解 doc2vec,下面提到的是我使用 Gensim 的代码。如我所愿,我得到了两个文档的训练模型和文档向量。
但是,我想知道在几个时期重新训练模型的好处以及如何在 Gensim 中进行?我们可以使用iter 或alpha 参数来做到这一点,还是我们必须在单独的for loop 中训练它?请让我知道我应该如何更改以下代码来训练模型 20 个 epoch。
另外,我很想知道 word2vec 模型是否也需要多次训练迭代。
# Import libraries
from gensim.models import doc2vec
from collections import namedtuple
# Load data
doc1 = ["This is a sentence", "This is another sentence"]
# Transform data
docs = []
analyzedDocument = namedtuple('AnalyzedDocument', 'words tags')
for i, text in enumerate(doc1):
words = text.lower().split()
tags = [i]
docs.append(analyzedDocument(words, tags))
# Train model
model = doc2vec.Doc2Vec(docs, size = 100, window = 300, min_count = 1, workers = 4)
# Get the vectors
model.docvecs[0]
model.docvecs[1]
【问题讨论】:
标签: python deep-learning word2vec gensim doc2vec