gensim의 ldamodel에는 get_document_topics
및 get_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.0까지 추가하지 않는 이유는 무엇입니까?
user
이 더 높은 확률을 갖는 주제 (숫자가model.show_topics()
)는 더 높은 번호가 할당되었지만이 숫자는 무엇을 의미합니까?get_term_topics
을 사용해야하는 이유는 무엇입니까?get_document_topics
이 동일한 기능을 제공 할 수 있고 의미있는 출력을 낼 수 있습니까?