2017-04-11 21 views
3

gensimのldamodelには、およびget_term_topicsという2つのメソッドがあります。このgensimチュートリアルnotebookでの使用にもかかわらずgensimのget_document_topicsおよびget_term_topics

、私は完全にget_term_topicsの出力を解釈する方法を理解し、私が何を意味するかを示すために、以下の自己完結型のコードを作成していない:

get_document_topicsについては
from gensim import corpora, models 

texts = [['human', 'interface', 'computer'], 
['survey', 'user', 'computer', 'system', 'response', 'time'], 
['eps', 'user', 'interface', 'system'], 
['system', 'human', 'system', 'eps'], 
['user', 'response', 'time'], 
['trees'], 
['graph', 'trees'], 
['graph', 'minors', 'trees'], 
['graph', 'minors', 'survey']] 

# build the corpus, dict and train the model 
dictionary = corpora.Dictionary(texts) 
corpus = [dictionary.doc2bow(text) for text in texts] 
model = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, num_topics=2, 
           random_state=0, chunksize=2, passes=10) 

# show the topics 
topics = model.show_topics() 
for topic in topics: 
    print topic 
### (0, u'0.159*"system" + 0.137*"user" + 0.102*"response" + 0.102*"time" + 0.099*"eps" + 0.090*"human" + 0.090*"interface" + 0.080*"computer" + 0.052*"survey" + 0.030*"minors"') 
### (1, u'0.267*"graph" + 0.216*"minors" + 0.167*"survey" + 0.163*"trees" + 0.024*"time" + 0.024*"response" + 0.024*"eps" + 0.023*"user" + 0.023*"system" + 0.023*"computer"') 

# get_document_topics for a document with a single token 'user' 
text = ["user"] 
bow = dictionary.doc2bow(text) 
print "get_document_topics", model.get_document_topics(bow) 
### get_document_topics [(0, 0.74568415806946331), (1, 0.25431584193053675)] 

# get_term_topics for the token user 
print "get_term_topics: ", model.get_term_topics("user", minimum_probability=0.000001) 
### get_term_topics: [(0, 0.1124525558321441), (1, 0.006876306738765027)] 

、出力は意味をなさない。 2つの確率は1.0になり、userが高い確率を持つトピック(model.show_topics())は、高い確率が割り当てられます。

しかしget_term_topicsのために、質問があります

  1. 確率は1.0、なぜにならないのですか?
  2. 数値的には、userが高い確率を持つトピック(model.show_topics())も高い数値が割り当てられていますが、この数字は何を意味していますか?
  3. get_term_topicsを使用する理由は何ですか。get_document_topicsは(一見)同じ機能を提供し、意味のある出力を得ることができますか?

答えて

3

私はLDAトピックモデリングに取り組んでいました。 topic1とtopic2という2つのトピックを作成しました。各トピックについて

トップ10の単語は次のとおりである。最終的に、私は最も近いトピックを決定するための1つの文書を取っ 0.009*"would" + 0.008*"experi" + 0.008*"need" + 0.007*"like" + 0.007*"code" + 0.007*"work" + 0.006*"think" + 0.006*"make" + 0.006*"one" + 0.006*"get

0.027*"ierr" + 0.018*"line" + 0.014*"0.0e+00" + 0.010*"error" + 0.009*"defin" + 0.009*"norm" + 0.006*"call" + 0.005*"type" + 0.005*"de" + 0.005*"warn

for d in doc: 
    bow = dictionary.doc2bow(d.split()) 
    t = lda.get_document_topics(bow) 

出力は[(0, 0.88935698141006414), (1, 0.1106430185899358)]です。

あなたの最初の質問に答えるために、確率はドキュメントに対して1.0まで追加され、それがget_document_topicsの機能です。文書は、(topic_id、topic_probability)2タプルのリストとして、指定された文書の弓のトピック分布を返すことを明確に述べている。

さらに、私はキーワード「IERR」

t = lda.get_term_topics("ierr", minimum_probability=0.000001)ためget_term_topicsしようとしましたが、結果は理にかなっている各トピックを決定するための単語の貢献に過ぎない[(1, 0.027292299843400435)]です。

get_document_topicsを使用して取得したトピックの分布に基づいてドキュメントにラベルを付けることができ、get_term_topicsによって与えられた寄与に基づいてその単語の重要性を判断できます。

こちらがお役に立てば幸いです。

関連する問題