2017-02-17 14 views
1

私はLDAモデルとドキュメントトピックの確率を持っています。gensim LdaModelでトピック単語確率行列を抽出します。

# build the model on the corpus 
ldam = LdaModel(corpus=corpus, num_topics=20, id2word=dictionary) 
# get the document-topic probabilities 
theta, _ = ldam.inference(corpus) 

また、すべてのトピック、すなわちトピック - 単語確率マトリックスについての単語の分布が必要です。この情報を抽出する方法はありますか?

ありがとうございます!あなたは確率分布をしたい場合は、単にそれを正規化

topics_terms = ldam.state.get_lambda() 

:経由

答えて

3

トピック期マトリックス(ラムダ)がアクセス可能である

topics_terms_proba = np.apply_along_axis(lambda x: x/x.sum(),1,topics_terms) 
+0

私は 'ldam.state.get_lambdaを(使用) '私は数の少ない行列を得るが、列名はない。どのように言葉を特定するのですか? –

+0

どの単語が特定のインデックスに対応しているか知るには、 'ldam.id2word'を使います。例えば ​​'ldam.id2word [0]'は行列の最初の列に対応する単語です。 – arthur

関連する問題