这是我在this thread中回复的内容。我试图在gensim中打印LSI主题时遇到了一些棘手的结果。这是我的代码:
try:
from gensim import corpora, models
except ImportError as err:
print err
class LSI:
def topics(self, corpus):
tfidf = models.TfidfModel(corpus)
corpus_tfidf = tfidf[corpus]
dictionary = corpora.Dictionary(corpus)
lsi = models.LsiModel(corpus_tfidf, id2word=dictionary, num_topics=5)
print lsi.show_topics()
if __name__ == '__main__':
data = '../data/data.txt'
corpus = corpora.textcorpus.TextCorpus(data)
LSI().topics(corpus)
这将以下内容输出到控制台。
-0.804*"(5, 1)" + -0.246*"(856, 1)" + -0.227*"(145, 1)" + ......
我希望能够打印出像@ 2er0的主题做了over here但我得到这样的结果。请参阅下面的内容并注意打印的第二项是一个元组,我不知道它来自哪里。 data.txt是一个包含几个段落的文本文件。就这些。
对此的任何想法都是太棒了!亚当
非常感谢您抽出时间来解决这个问题!我们现在很好... – aeupinhere 2013-03-12 02:58:46