为什么在处理单个文档和批量文档时,MALLET主题推断结果不同?

我在使用MALLET 2.0.7进行LDA主题建模。我可以训练一个LDA模型,并且根据训练过程的输出来看,效果不错。此外,我可以使用该过程中构建的推断器,在重新处理我的训练文件时得到相似的结果。然而,如果我从更大的训练集中取出一个单独的文件,并用推断器处理它,我得到的结果却大不相同,而且效果不好。

我的理解是,推断器应该使用一个固定的模型,并且只使用该文档的本地特征,所以我不明白为什么在处理一个文件或训练集中的1000个文件时会得到不同的结果。我没有进行频率截断,这似乎是一种会产生这种影响的全局操作。您可以在下面的命令中看到我使用的其他参数,但它们大多是默认的。将迭代次数改为0或100也没有帮助。

导入数据:

bin/mallet import-dir \  --input trainingDataDir \  --output train.data \  --remove-stopwords TRUE \  --keep-sequence TRUE \  --gram-sizes 1,2 \  --keep-sequence-bigrams TRUE

训练:

time ../bin/mallet train-topics  --input ../train.data \  --inferencer-filename lda-inferencer-model.mallet \  --num-top-words 50 \  --num-topics 100 \  --num-threads 3 \  --num-iterations 100 \  --doc-topics-threshold 0.1 \  --output-topic-keys topic-keys.txt \  --output-doc-topics doc-topics.txt

在训练过程中分配给特定文件的主题,其中#14是关于葡萄酒的,这是正确的:

998 file:/.../29708933509685249 14  0.31684981684981683 > grep "^14\t" topic-keys.txt 14  0.5 wine spray cooking car climate top wines place live honey sticking ice prevent collection market hole climate_change winery tasting california moldova vegas horses converted paper key weather farmers_market farmers displayed wd freezing winter trouble mexico morning spring earth round mici torrey_pines barbara kinda nonstick grass slide tree exciting lots 

对整个训练批次运行推断:

../bin/mallet infer-topics \  --input ../train.data \  --inferencer lda-inferencer-model.mallet \  --output-doc-topics inf-train.1 \  --num-iterations 100

训练集上的推断得分 – 非常相似:

998 /.../29708933509685249 14 0.37505087505087503 

对仅包含该1个txt文件的另一个训练数据文件运行推断:

../bin/mallet infer-topics \  --input ../one.data \  --inferencer lda-inferencer-model.mallet \  --output-doc-topics inf-one.2 \  --num-iterations 100

对单个文档进行推断产生了主题80和36,这与之前大不相同(主题14的得分接近0):

0 /.../29708933509685249 80 0.3184778184778185 36 0.19067969067969068> grep "^80\t" topic-keys.txt 80  0.5 tips dog care pet safety items read policy safe offer pay avoid stay important privacy services ebay selling terms person meeting warning poster message agree sellers animals public agree_terms follow pets payment fraud made privacy_policy send description puppy emailed clicking safety_tips read_safety safe_read stay_safe services_stay payment_services transaction_payment offer_transaction classifieds_offer 

回答:

问题出在small.dataone.data训练数据文件之间的不兼容性。尽管我小心翼翼地使用了所有相同的选项,但默认情况下,两个数据文件会使用不同的字母表(单词与整数之间的映射)。为了纠正这个问题,使用–use-pipe-from [MALLET TRAINING FILE]选项,然后指定其他选项似乎是不必要的。感谢David Mimno的帮助。

bin/mallet import-dir \  --input [trainingDataDirWithOneFile] \  --output one.data \  --use-pipe-from small.data 

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注