
320
■
21
章 自然言語処理
topic_counts[topic] -= 1
document_lengths[d] -= 1
#
重みに従い、新しいトピックを割り当てる
new_topic = choose_new_topic(d, word)
document_topics[d][i] = new_topic
#
新しいトピックでカウンターを更新する
document_topic_counts[d][new_topic] += 1
topic_word_counts[new_topic][word] += 1
topic_counts[new_topic] += 1
document_lengths[d] += 1
トピックは
1, 2, 3
といった単なる数値として扱ってきました。それらに名前を与える
のはデータから行います。各トピックに割り当てられた単語を重み順に見てみましょう
(表 21-1)。
for k, word_counts in enumerate(topic_word_counts):
for word, count in word_counts.most_common():
if count > 0:
print(k, word, count)
表 21-1 トピックごとの頻出単語
Topic 0 Topic 1 Topic 2 Topic 3
Java R HBase regression
Big Data statistics Postgres libsvm