Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.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加载LdaMallet模型并对不可见文档进行分类的正确方法_Python_Gensim_Lda_Mallet - Fatal编程技术网

Python 使用gensim加载LdaMallet模型并对不可见文档进行分类的正确方法

Python 使用gensim加载LdaMallet模型并对不可见文档进行分类的正确方法,python,gensim,lda,mallet,Python,Gensim,Lda,Mallet,在我的项目中,我使用Python库对文本进行主题建模/提取。 我尝试加载我训练过的LdaMallet模型来对新的看不见的文本进行分类 第一部分是加载模型 import os dirname = os.path.dirname(__file__) filename = os.path.join(dirname, 'mallet-2.0.8/bin/mallet') # Download File: http://mallet.cs.umass.edu/dist/mallet-2.0.8.zip

在我的项目中,我使用Python库对文本进行主题建模/提取。 我尝试加载我训练过的LdaMallet模型来对新的看不见的文本进行分类

第一部分是加载模型

import os

dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, 'mallet-2.0.8/bin/mallet')

# Download File: http://mallet.cs.umass.edu/dist/mallet-2.0.8.zip
os.environ['MALLET_HOME'] = # path to mallet

ldaMallet = gensim.models.wrappers.LdaMallet.load('lda_malletoutputCommentsAndMethods.model)
ldaModel = gensim.models.wrappers.ldamallet.malletmodel2ldamodel(ldaMallet)
我不确定将ldaMallet转换为LdaModel的最后一行是什么。这是获得一些结果的唯一途径

第二部分是准备新数据并对其进行分类

from gensim.test.utils import common_dictionary
other_texts = [['new', 'document', 'to', 'classify', 'as', 'array']]
other_corpus = [common_dictionary.doc2bow(text) for text in other_texts]
vector = ldaModel[other_corpus[0]]

# sorts the result by probability and not by topic ID
print(sorted(vector, key=lambda x: x[1], reverse=True))
结果如下所示:

[(16, 0.143), (17, 0.08), (9, 0.0653),...]

无论我在
其他_文本
数组中使用哪个文本,这个结果都不会改变,但应该会改变

Print(ldaModel[other_corpus[0])Print(ldaModel[other_corpus[4])和Print(ldaModel[other_corpus[:])对于我来说,我有几篇文章将预先训练好的LDA应用到一个新的数据集,但从来没有从一个单独的文件位置。我想象迭代步骤是类似的