为什么在处理单个文档和批量文档时,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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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