gpt4 book ai didi

nlp - 为什么使用 MALLET 主题推断对单个文档和批量文档会得到不同的结果?

转载 作者:行者123 更新时间:2023-11-30 08:24:41 29 4
gpt4 key购买 nike

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

我的理解是,推理器应该使用固定模型,并且仅具有该文档的本地特征,因此我不明白为什么在处理 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

火车:

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 是关于 wine 的,这是正确的:

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] 选项,然后指定其他选项似乎是不必要的。感谢大卫·米诺。

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

关于nlp - 为什么使用 MALLET 主题推断对单个文档和批量文档会得到不同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7636959/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com