Gensimの組み込みメソッドshow_topicを使用して、LDAモデルからtopn単語を取得できます。
lda = models.LdaModel.load('lda.model')
for i in range(0, lda.num_topics):
with open('output_file.txt', 'w') as outfile:
outfile.write('{}\n'.format('TopiC#' + str(i + 1) + ': '))
for word, prob in lda.show_topic(i, topn=20):
outfile.write('{}\n'.format(word.encode('utf-8')))
outfile.write('\n')
これは、このような形式のファイルを書き込みます:
TopiC#69:
pet
dental
tooth
adopt
animal
puppy
rescue
dentist
adoption
animal
shelter
pet
dentistry
vet
paw
pup
patient
mix
foster
owner
TopiC#70:
periscope
disneyland
disney
snapchat
brandon
britney
periscope
periscope
replay
britneyspear
buffaloexchange
britneyspear
https
meerkat
blab
periscope
kxci
toni
disneyland
location
あなたがたりないかもしれない、あなたのニーズにこれを調整する必要があり、すなわち代わりに出力の上位20単語のリストを生成しますそれをテキストファイルに変換します。
この記事の答えは、原文を使って単語の雲を作成する方法の良い説明です。 How do I print lda topic model and the word cloud of each of the topics
@JulienBernuはい私は持っています。モデルオブジェクトには、各トピックの単語ではなく、トピックの属性があります。概念的な難点はありません。私はこれらの単語を他の変数に抽出する方法を知らないだけです。 –