简体   繁体   English

如何使用gensim查看和解释lda模型的输出

[英]How to view and interpret the output of lda model using gensim

I am able to create the lda model and save it.我能够创建 lda 模型并保存它。 Now I am trying load the model, and pass a new document现在我正在尝试加载模型,并传递一个新文档

lda = LdaModel.load('..\\\\models\\\\lda_v0.1.model') doc_lda = lda[new_doc_term_matrix] print(doc_lda )

On printing the doc_lda I am getting the object.在打印 doc_lda 时,我得到了对象。 <gensim.interfaces.TransformedCorpus object at 0x000000F82E4BB630> However I want to get the topic words associated with it. <gensim.interfaces.TransformedCorpus object at 0x000000F82E4BB630>但是我想获取与之相关的主题词。 What is the method I have to use.我必须使用什么方法。 I was referring to this .我指的是这个

Not sure if this is still relevant, but have you tried get_document_topics() ?不确定这是否仍然相关,但是您是否尝试过get_document_topics() Though I assume that would only work if you've updated your LDA model using update() .尽管我认为这仅在您使用update()更新了 LDA 模型时才有效。

I don't think there is anything wrong with your code - the "Usage example" from the documentation link you posted uses doc2bow which returns a sparse vector - I don't know what new_doc_term_matrix consists of, but I'll assume it worked fine.我认为您的代码没有任何问题 - 您发布的文档链接中的“用法示例”使用doc2bow返回一个稀疏向量 - 我不知道new_doc_term_matrix由什么组成,但我认为它工作正常.

You might want to look at this stackoverflow question : you want to print an "object" - that isn't printable, the data you want is somewhere in the object, and that in itself is printable.你可能想看看这个 stackoverflow 问题:你想print一个“对象”——它是不可打印的,你想要的数据在对象的某个地方,而且它本身是可打印的。

Alternatively, you can also use your IDE's capabilities - the Variable explorer in Spyder, for example - to click yourself into the objects and get the info you need.或者,您也可以使用 IDE 的功能(例如,Spyder 中的变量资源管理器)将自己单击到对象中并获取所需信息。

For more info on similarity analysis with gensim, see this tutorial .有关使用 gensim 进行相似性分析的更多信息,请参阅本教程

使用这个doc_lda.print_topics(-1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM