为什么单个和批量文档的MALLET主题推断得到不同的结果?

Joh*_*ann 8 nlp machine-learning mallet topic-modeling

我正在尝试使用Mallet 2.0.7执行LDA主题建模.根据训练课程的输出,我可以训练LDA模型并获得良好的结果.此外,我可以使用该过程中内置的inferencer,并在重新处理我的训练文件时获得类似的结果.但是,如果我从较大的训练集中获取单个文件,并使用推理器处理它,我会得到非常不同的结果,这是不好的.

我的理解是推理器应该使用固定模型,并且只有该文档的本地特征,所以我不明白为什么在处理1个文件或我的训练集中的1k时会得到任何不同的结果.我没有做频率截止,这似乎是一种具有这种效果的全局操作.你可以在下面的命令中看到我正在使用的其他参数,但它们大部分都是默认的.将迭代次数更改为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
Run Code Online (Sandbox Code Playgroud)

培养:

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
Run Code Online (Sandbox Code Playgroud)

培训期间分配给一个文件的主题,特别是#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 
Run Code Online (Sandbox Code Playgroud)

对整批列车进行推断:

../bin/mallet infer-topics \
  --input ../train.data \
  --inferencer lda-inferencer-model.mallet \
  --output-doc-topics inf-train.1 \
  --num-iterations 100
Run Code Online (Sandbox Code Playgroud)

火车上的推理得分 - 非常相似:

998 /.../29708933509685249 14 0.37505087505087503 
Run Code Online (Sandbox Code Playgroud)

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

../bin/mallet infer-topics \
  --input ../one.data \
  --inferencer lda-inferencer-model.mallet \
  --output-doc-topics inf-one.2 \
  --num-iterations 100
Run Code Online (Sandbox Code Playgroud)

对一个文档的推断产生了主题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 
Run Code Online (Sandbox Code Playgroud)

Joh*_*ann 10

问题是small.dataone.data训练数据文件之间不兼容.即使我小心使用所有相同的选项,默认情况下两个数据文件将使用不同的字母表(单词和整数之间的映射).要更正此问题,请使用 - [MALLET TRAINING FILE]选项中的--use-pipe-,然后指定其他选项似乎是不必要的.感谢David Mimno.

bin/mallet import-dir \
  --input [trainingDataDirWithOneFile] \
  --output one.data \
  --use-pipe-from small.data 
Run Code Online (Sandbox Code Playgroud)