我正在使用ldamodel
训练我的gensim
,并预测使用像这个ldamodel[doc_term_matrix_test]
这样的测试语料库,它工作正常,但我不明白预测是如何使用训练模型实际完成的(ldamodel[doc_term_matrix_test]
正在做什么)。
这是代码:
dictionary2 = corpora.Dictionary(test)
dictionary = corpora.Dictionary(train)
dictionary.merge_with(dictionary2)
doc_term_matrix2 = [dictionary.doc2bow(doc) for doc in test]
doc_term_matrix = [dictionary.doc2bow(doc) for doc in train]
Lda = gensim.models.ldamodel.LdaModel
ldamodel = Lda(doc_term_matrix, num_topics=2, id2word =
dictionary,random_state=100, iterations=50, passes=1)
topics = sorted(ldamodel[doc_term_matrix2],
key=lambda
x:x[1],
reverse=True)
该模块允许从训练语料库中估计LDA模型,并在新的,看不见的文档上推断主题分布。
显然,你的代码所做的不是“预测”,而是推理。也就是说,您训练的LDA模型为每个测试文档生成T
,估计T
的主题分布。