首页 > 解决方案 > Gensim LSI 方法 show_topics 返回的概率为什么是负数?

问题描述

(0,'0.707*“ + 0.707*” + + -0.000“ + -0.000 + + -0.000*“ +' +' +'0.000*” + 0.000*“ + 0.000*” + 0.000* *"ऑफ़" + ' '-0.000 "युन" + -0.000 "स्थली" *')]
如文档所述
show_topics(num_topics=-1, num_words=10, log=False, formatted=True)
返回最重要的 num_topics主题(默认全部返回)。对于每个主题,显示 num_words 个最重要的词(默认为 10 个词)。

主题以列表形式返回——如果格式化为 True,则返回字符串列表,如果为 False,则返回(单词、概率)2 元组列表。

如果 log 为 True,也将此结果输出到 log。

def preprocessing(corpus):
    for document in corpus:
        doc = strip_short(document,3)
        doc = strip_punctuation(doc)
        yield word_tokenize(doc)
texts = preprocessing(corpus)
dictionary = corpora.Dictionary(texts)
dictionary.filter_extremes(no_below=1, keep_n=25000)

doc_term_matrix = [dictionary.doc2bow(tokens) for tokens in preprocessing(corpus)]
tfidf = models.TfidfModel(doc_term_matrix)
corpus_tfidf = tfidf[doc_term_matrix]

lsi = models.LsiModel(corpus_tfidf, id2word=dictionary)
pprint(lsi.show_topics(num_topics=4, num_words=10))
[(0,
  '0.707*"उत्तरपश्चिमी" + 0.707*"यूरोप" + -0.000*"बुद्ध" + -0.000*"जन्म" + '
  '0.000*"बेल्जियम" + 0.000*"किंगडम" + 0.000*"नेपाल" + 0.000*"ऑफ़" + '
  '-0.000*"युन" + -0.000*"स्थली"'),
 (1,
  '0.577*"किंगडम" + 0.577*"बेल्जियम" + 0.577*"ऑफ़" + -0.000*"जन्म" + '
  '-0.000*"बुद्ध" + -0.000*"भगवान" + -0.000*"स्थित" + -0.000*"लुंबिनी" + '
  '-0.000*"उत्तरपश्चिमी" + -0.000*"यूरोप"'),
 (2,
  '0.354*"जन्म" + 0.354*"भगवान" + 0.354*"स्थित" + 0.354*"स्थली" + 0.354*"युन" '
  '+ 0.354*"बुद्ध" + 0.354*"लुंबिनी" + 0.354*"नेपाल" + 0.000*"उत्तरपश्चिमी" + '
  '0.000*"यूरोप"')]

标签: pythonnlpgensim

解决方案


感谢您使用 SO。

show_topics为您提供语料库中最重要的主题。您看到的概率是每个单词对主题的贡献。例如,“उत्तरपश्चिमी”和“यूरोप”的贡献分别为 0.707,而“बेल्जियम”的贡献为 0.000。

在显示单词的贡献时,模型显示了最大的绝对值,但由于截断了接近 0 的浮点数(例如 -0.0000008),它们显示为 -0.00。

参考资料:https ://radimrehurek.com/gensim/models/lsimodel.html


推荐阅读