我得到了一个使用 gensim 的 doc2vec 模型,该模型在 2000 万个文档上进行了训练。它训练的 2000 万份文件也给了我,但我不知道这些文件是如何或以何种顺序从文件夹中训练的。我应该使用测试数据从训练集中找到前 10 个匹配项。我使用的代码是 -
model = gensim.models.doc2vec.Doc2Vec.load("doc2vec_sample.model")
test_docs=["This is the test set I want to test on."]
def read_corpus(documents, tokens_only=False):
count=0
count=count+1
for line in documents:
if tokens_only:
yield gensim.utils.simple_preprocess(line)
else:
# For training data, add tags
yield gensim.models.doc2vec.TaggedDocument(gensim.utils.simple_preprocess(line), [count])
test_corpus = list(read_corpus(test_docs, tokens_only=True))
doc_id=0
inferred_vector = model.infer_vector(test_corpus[doc_id])
maxx=10
sims = model.docvecs.most_similar([inferred_vector], topn=maxx)
for match in sims:
print match
` 我得到的输出是 -
(1913, 0.4589531719684601)
(3250, 0.4300411343574524)
(1741, 0.42669129371643066)
(1, 0.4023148715496063)
(1740, 0.3929900527000427)
(1509, 0.39229822158813477)
(3189, 0.387174129486084)
(3145, 0.3842133581638336)
(1707, 0.3813004493713379)
(3200, 0.3754497170448303)
我如何知道文档 ID“1913”指的是哪个文档?如何从这 10 个工作 ID 中访问训练数据集的文档?