我必須應用LDA(潛在Dirichlet分配)從我收集的20,000個文檔的數據庫中獲取可能的主題。我們可以使用自制語料庫進行使用gensim的LDA培訓嗎?
如何使用這些文檔而不是像布朗語料庫或英語維基百科這樣的其他語料庫作爲訓練語料庫?
您可以參考this頁面。
我必須應用LDA(潛在Dirichlet分配)從我收集的20,000個文檔的數據庫中獲取可能的主題。我們可以使用自制語料庫進行使用gensim的LDA培訓嗎?
如何使用這些文檔而不是像布朗語料庫或英語維基百科這樣的其他語料庫作爲訓練語料庫?
您可以參考this頁面。
閱讀Gensim軟件包的文檔後,我發現總共有4種將文本庫轉換爲語料庫的方法。
總共有4種格式胼:
在此問題中,如上所述,數據庫中共有19,188個文檔。 必須閱讀每個文檔並從句子中刪除停用詞和標點符號,這可以使用nltk
完成。
import gensim
from gensim import corpora, similarities, models
##
##Text Preprocessing is done here using nltk
##
##Saving of the dictionary and corpus is done here
##final_text contains the tokens of all the documents
dictionary = corpora.Dictionary(final_text)
dictionary.save('questions.dict');
corpus = [dictionary.doc2bow(text) for text in final_text]
corpora.MmCorpus.serialize('questions.mm', corpus)
corpora.SvmLightCorpus.serialize('questions.svmlight', corpus)
corpora.BleiCorpus.serialize('questions.lda-c', corpus)
corpora.LowCorpus.serialize('questions.low', corpus)
##Then the dictionary and corpus can be used to train using LDA
mm = corpora.MmCorpus('questions.mm')
lda = gensim.models.ldamodel.LdaModel(corpus=mm, id2word=dictionary, num_topics=100, update_every=0, chunksize=19188, passes=20)
這樣一個可以改變他的數據集,可以使用LDA使用gensim包主題建模進行訓練語料庫。
你有鏈接到這些格式的例子嗎? – 2015-04-09 12:48:05
@PiotrMigdal嗨,你可以看看[這裏](https://radimrehurek.com/gensim/tut1.html#corpus-formats)。 – 2015-04-09 17:56:51
我已經看過那裏,但沒有任何示例(即具有給定格式的幾行文件)。在http://cscorley.github.io/2014/05/06/using-gensim-for-lda/上只有一個「槌子」的例子。 – 2015-04-09 18:00:56
這個問題有點不確定;如果您可以更具體地瞭解您迄今爲止所嘗試的內容以及您遇到的具體問題,則可能更有可能獲得答案。 – ASGM 2013-04-27 16:10:21
我編輯了這個問題! – 2013-04-27 16:23:35
如果你不喜歡它,只需投票結束它。 – 2013-04-27 16:30:01