2017-04-11 3 views
3

gensim의 ldamodel에는 get_document_topicsget_term_topics의 두 가지 메소드가 있습니다. 이 gensim 튜토리얼 notebook에서의 사용에도 불구하고 get_document_topics 및 get_term_topics gensim

, 나는 완전히 아래 무슨 뜻인지 보여 get_term_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)] 

get_document_topics의 내용은 출력이 의미가 있습니다. 두 확률은 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라는 두 가지 주제를 만들었습니다. 다음과 같이

각 주제에 대한 10 단어는 다음과 같습니다

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

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

는 결국, 나는 가장 가까운 항목을 결정하는 1 문서를했다.

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-tuples의 목록으로 주어진 문서 활에 대한 토픽 분포를 반환한다는 것을 명확하게 기술하고있다.

또한, 나는 키워드 "IERR"

t = lda.get_term_topics("ierr", minimum_probability=0.000001)에 대한 get_term_topics하기 위해 노력하고 결과는 의미가 각 주제를 결정하는 단어 기여에 불과하다 [(1, 0.027292299843400435)]이다.

그래서 get_document_topics를 사용하여 얻은 주제 분포를 기반으로 문서에 레이블을 지정할 수 있으며 get_term_topics가 제공 한 기여도에 따라 단어의 중요성을 결정할 수 있습니다.

이 정보가 도움이되기를 바랍니다.