Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python gensim-LdaModel中主题词概率矩阵的提取_Python_Gensim_Lda_Topic Modeling - Fatal编程技术网

Python gensim-LdaModel中主题词概率矩阵的提取

Python gensim-LdaModel中主题词概率矩阵的提取,python,gensim,lda,topic-modeling,Python,Gensim,Lda,Topic Modeling,我有LDA模型和文档主题概率 # build the model on the corpus ldam = LdaModel(corpus=corpus, num_topics=20, id2word=dictionary) # get the document-topic probabilities theta, _ = ldam.inference(corpus) 我还需要所有主题的词分布,即主题词概率矩阵。有没有办法提取这些信息 谢谢 可通过以下方式访问主题术语表(lambda): t

我有LDA模型和文档主题概率

# build the model on the corpus
ldam = LdaModel(corpus=corpus, num_topics=20, id2word=dictionary) 
# get the document-topic probabilities
theta, _ = ldam.inference(corpus)
我还需要所有主题的词分布,即主题词概率矩阵。有没有办法提取这些信息

谢谢

可通过以下方式访问主题术语表(lambda):

topics_terms = ldam.state.get_lambda()
如果您想要概率分布,只需将其标准化:

topics_terms_proba = np.apply_along_axis(lambda x: x/x.sum(),1,topics_terms)

当我使用ldam.state.get_lambda()时,我得到一个numpy矩阵,但是没有列名。如何识别单词?要知道哪个单词对应于给定索引,请使用
ldam.id2word
。例如,
ldam.id2word[0]
是对应于矩阵第一列的单词。