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