[英]Is there a method in Gensim to find the most relevant topics between two corpuses?
[英]Gensim find topics in sentences
我已經在語料庫上訓練了LDA算法,我想要做的是為每個句子獲取與之對應的主題,以便在算法找到的內容和我擁有的標簽之間進行比較。
我已經嘗試使用下面的代碼,但是結果非常糟糕,我發現了很多有關主題17的內容(可能是25%,應該接近5%)
謝謝你的幫助
# text lemmatized: list of string lemmatized
dico = Dictionary(texts_lemmatized)
corpus_lda = [dico.doc2bow(text) for text in texts_lemmatized]
lda_ = LdaModel(corpus_lda, num_topics=18)
df_ = pd.DataFrame([])
data = []
# theme_commentaire = label of the string
for i in range(0, len(theme_commentaire)):
# lda_.get_document_topics() gives the distribution of all topic for a specific sentence
algo = max(lda_.get_document_topics(corpus_lda[i]))[0]
human = theme_commentaire[i]
data.append([str(algo), human])
cols = ['algo', 'human']
df_ = pd.DataFrame(data, columns=cols)
df_.head()
解決的評論:
不過,我發現了我的問題,它是max()函數,它對我的元組列表的鍵值[(num_topics,概率)]起作用,因此基本上我大部分時間都會得到17,因為它是最大的鍵。 –格洛瓦
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.