2011-10-03 64 views
8

我正在嘗試使用Mallet 2.0.7執行LDA主題建模。根據培訓課程的輸出結果,我可以訓練LDA模型並取得好成績。此外,我可以使用該過程中構建的推理器,並在重新處理訓練文件時獲得類似的結果。但是,如果我從較大的訓練集中獲取單個文件,並使用推理程序處理它,則會得到非常不同的結果,這些結果並不理想。爲什麼通過MALLET主題推斷獲得與單個和批量文檔不同的結果?

我的理解是推理者應該使用固定模型,並且只對該文檔具有本地特徵,所以我不明白爲什麼在處理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是關於酒這是正確的:

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 

回答

10

該p roblem是small.dataone.data培訓數據文件之間的不兼容。儘管我一直很小心地使用所有相同的選項,但兩個數據文件默認使用不同的字母(單詞和整數之間的映射)。爲了解決這個問題,使用[MALLET TRAINING FILE]選項中的--use-pipe-from,然後指定其他選項似乎是不必要的。感謝David Mimno。

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