【发布时间】:2018-12-11 01:01:47
【问题描述】:
一直在关注文档here 以及此链接:Machine Learning Gensim Tutorial,我完全不知道为什么会发生这种情况。在对我的句子进行标记和词形还原之后,我将句子放入短语中,创建了一个字典,并将所有正确的变量插入到模型中。这是我的代码示例:
tokens = [[euid, sent, gensim.parsing.preprocessing.preprocess_string(sent.lower(), filters=[strip_punctuation,
strip_multiple_whitespaces, strip_numeric, remove_stopwords, strip_short, wordnet_stem])] for sent in sentences]
#these filters are all default gensim filters except for wordnet_stem, which uses a WordNetLemmatizer
bigram = gensim.models.Phrases(bag_of_words)
bigram_mod = gensim.models.phrases.Phraser(bigram)
示例令牌列表如下所示:['beautiful', 'Manager', 'tree', 'caring', 'great_place'](完全虚构的列表)
texts = [bigram_mod[t] for t in bag_of_words]
id2word = corpora.Dictionary(texts)
sent_wordfreq = [id2word.doc2bow(sent) for sent in texts]
lda_model = gensim.models.ldamodel.LdaModel(corpus=sent_wordfreq,
id2word=id2word,
num_topics=5,
update_every=1,
alpha='auto',
per_word_topics=True)
这是我得到的主题:
[(0, 'nan*"发现" + nan*"获得" + nan*"发送" + ... (1, 'nan*"发现" + nan*"获得" + nan*"发送" + ... 并且这种情况又持续了 3 次
所以不仅所有主题都相同,而且每个主题的权重都是 nan。可能是什么问题?
【问题讨论】:
标签: python pandas nlp gensim lda