python - 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*"यूरोप"')]
解决方案
感谢您使用 SO。
show_topics为您提供语料库中最重要的主题。您看到的概率是每个单词对主题的贡献。例如,“उत्तरपश्चिमी”和“यूरोप”的贡献分别为 0.707,而“बेल्जियम”的贡献为 0.000。
在显示单词的贡献时,模型显示了最大的绝对值,但由于截断了接近 0 的浮点数(例如 -0.0000008),它们显示为 -0.00。
推荐阅读
- javascript - 过滤时找不到数据时如何显示错误消息
- c# - 如何使用 RaspberryPi 在 asp.net mvc 中编写 windows 窗体或 web 应用程序?
- python - 使用 PyRFC 提取 RAW 数据类型列的问题
- vb.net - 我无法通过 Visual Basic 将新行保存到 Microsoft Access 数据库中
- ios - 如何使用核心数据将对象传递给 SwiftUI 中的其他视图
- python - 使用 zip 函数返回一个空元组
- azure-repos - 有什么方法可以在 Visual Studio 中获取有关其他成员在我的 azure 存储库中提交的新提交的通知?
- java - AtomicReference#compareAndSet 阻塞了主线程,我应该使用同步吗?
- html - ngClass 在我的 Angular 项目中不起作用
- codenameone - MediaPlayer 在 HLS 流式传输结束时在 Android 上生成“无法播放此视频”错误