Gensim LdaSeqModel出现时间切片未收录词汇被分配非零概率的问题求助
Gensim LdaSeqModel出现时间切片未收录词汇被分配非零概率的问题求助
我在使用Python的Gensim包中的动态主题模型LdaSeqModel()时,碰到了一个逻辑上说不通的问题——模型会给某个时间切片里从未出现过的词汇分配非零概率,这明显不符合预期。我发现Gensim相关讨论里也有人提过这个尚未解决的问题,下面是我复现该问题的完整过程:
from gensim.corpora import Dictionary from gensim.models import LdaSeqModel common_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'] ] common_dictionary = Dictionary(common_texts) common_corpus = [common_dictionary.doc2bow(text) for text in common_texts] model = LdaSeqModel(corpus=common_corpus, id2word=common_dictionary, num_topics=1, time_slice=[5, 4]) model.print_topic_times(topic=0)
这里time_slice=[5, 4]表示第一个时间切片包含common_texts列表的前5篇文档,而词汇graph根本没有出现在第一个时间切片里,但运行model.print_topic_times(topic=0)输出的结果中,第一个时间切片里却有graph的非零概率:
[[('system', 0.13896054593348167), ('user', 0.10696589214152682), ('trees', 0.10664464447111177), ('graph', 0.10643809153102356), ('computer', 0.07494460648968987), ('human', 0.07494460648968987), ('interface', 0.07494460648968987), ('response', 0.07494460648968987), ('time', 0.07494460648968987), ('eps', 0.07494460648968987), ('minors', 0.07474199433434457), ('survey', 0.01658119265037265)], [('system', 0.13882862152464212), ('graph', 0.10742799576320598), ('trees', 0.10713473662111127), ('user', 0.1064043188010877), ('minors', 0.07517325760789559), ('computer', 0.07474729274679391), ('human', 0.07474729274679391), ('interface', 0.07474729274679391), ('response', 0.07474729274679391), ('time', 0.07474729274679391), ('eps', 0.07474729274679391), ('survey', 0.01654731320129382)]]
我已经尝试调整了alphas、passes和em_min_iter这些参数,但问题依然存在。想请教各位,有没有其他参数设置或者解决方法能让模型正确识别每个时间切片中实际存在的词汇,避免这种不符合逻辑的概率分配?
备注:内容来源于stack exchange,提问作者hyco




