簡體   English   中英

主題建模:LDA 模型中每個主題的 WordCloud

[英]Topic Modelling: WordCloud For Every Topic in LDA model

問題:如何為 LDA 模型計算的每個主題創建一個詞雲。 我嘗試了以下方法,但似乎無法進一步為每個主題創建一個詞雲。

first_topic = lda.components_[0]
second_topic = lda.components_[1]
third_topic = lda.components_[2]
fourth_topic = lda.components_[3]

firstcloud = WordCloud(
                      background_color='black',
                      width=2500,
                      height=1800
                     ).generate(" ".join(first_topic))
plt.imshow(firstcloud)
plt.axis('off')
plt.show()

你可以試試這個:

def create_wordcloud(model, topic):
    text = {word: value for word, value in model.show_topic(topic)}
    wc = WordCloud(background_color="white", max_words=1000)
    wc.generate_from_frequencies(text)
    plt.imshow(wc, interpolation="bilinear")
    plt.axis("off")
    plt.title("Topic" + " "+ str(topic))
    plt.show()

然后調用這個函數如下:

for i in range(1,num_topics):
    create_wordcloud(lda_model, topic=i)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM