python - 如何通过 gensim 将训练集的分布保存在经过训练的 LDA 模型上?

标签 python lda gensim

代码的最后部分:

lda = models.LdaModel(corpus_tfidf, id2word = dic, num_topics = 64)
corpus_lda = lda[corpus_tfidf]

我想知道如何保存corpus_lda以供进一步使用?

最佳答案

Gensim 具有将语料库写入磁盘的功能:

from Gensim import corpora
corpora.MmCorpus.serialize('pathandfilename.mm', corpus_lda) 

要加载已保存的语料库,请使用:

corpus_lda = corpora.MmCorpus('pathandfilename.mm')

还有类似的保存模型的功能(查看教程或 references )。 有不同的语料库格式可用,我相信矩阵市场曾经是 Gensim 使用的标准格式,但最近添加了索引语料库格式,它具有一些附加功能(索引,正如您可能已经猜到的那样)。

关于python - 如何通过 gensim 将训练集的分布保存在经过训练的 LDA 模型上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27354912/

相关文章:

python-3.x - LDA Mallet CalledProcessError

apache-spark - Spark 2.1.1 : How to predict topics in unseen documents on already trained LDA model in Spark 2. 1.1?

Gensim Doc2Vec 对未见过单词的 infer_vector 根据这些单词中的字符而有所不同

python - 使用 try except 时递归打印异常详细信息

python - 在python中制作两对的有效方法

python - pandas 计算每月平均值

python 3嵌套理解

gensim - 如何在 gensim LDA 中获取给定单词的主题词概率?

python - 在 Python 中使用 Gensim 进行主题建模

python - 理解 LDA/主题建模——主题重叠太多