gensimで平均化したPV-DMの実装を理解しようとしています。 train_document_dm
がdoc2vec.py
の場合、train_cbow_pair
の戻り値( "errors")は、平均化の場合(cbow_mean=1
)は入力ベクトルの数(count
)で除算されません。 この説明によれば、入力ベクトルを平均化する場合の文書数で除算する必要があります:word2vec Parameter Learning Explained, equation (23)。gensimのdoc2vec(PV-DM)のドキュメント・ベクトルの更新
l1 = np_sum(word_vectors[word2_indexes], axis=0)+np_sum(doctag_vectors[doctag_indexes], axis=0)
count = len(word2_indexes) + len(doctag_indexes)
if model.cbow_mean and count > 1:
l1 /= count
neu1e = train_cbow_pair(model, word, word2_indexes, l1, alpha,
learn_vectors=False, learn_hidden=learn_hidden)
if not model.cbow_mean and count > 1:
neu1e /= count
if learn_doctags:
for i in doctag_indexes:
doctag_vectors[i] += neu1e * doctag_locks[i]
if learn_words:
for i in word2_indexes:
word_vectors[i] += neu1e * word_locks[i]