LdaModel - random_state参数无法识别 - gensim

时间:2016-09-02 14:33:13

标签: python-3.x numpy gensim topic-modeling

我正在使用gensim的{​​{1}},根据documentationLdaModel具有参数random_state。但是,我收到的错误是:

 TypeError: __init__() got an unexpected keyword argument 'random_state'

如果没有random_state参数,该函数将按预期工作。因此,对于那些想要了解其他事情的人来说,工作流程看起来像这样......

from gensim import corpora, models
import numpy as np

# pseudo code of text pre-processing all on "comments" variable
# stop words
# remove punctuation (optional)
# keep alpha only
# stemming
# get bigrams and integrate with corpus (gensim makes this very easy)


dictionary = corpora.Dictionary(comments)
corpus = [dictionary.doc2bow(comm) for comm in comments]
tfidf = models.TfidfModel(corpus) # change weights
corp_tfidf = tfidf[corpus] # apply them to corpus

# set random seed
random_seed = 135
state = np.random.RandomState(random_seed)

# train model
num_topics = 3
lda_mod = models.LdaModel(corp_tfidf, # corpus
                          num_topics=num_topics, # number of topics we want back
                          id2word=dictionary, # our id-word map
                          passes=10, # how many passes to take over the data
                          random_state=state) # reproduce the results

导致上面的错误消息...

TypeError: __init__() got an unexpected keyword argument 'random_state'

如果可能的话,我希望能够重新创建我的结果。

1 个答案:

答案 0 :(得分:1)

根据thisrandom_state参数已添加到最新版本(0.13.2)中。您可以使用pip install gensim --upgrade更新您的gensim安装。您可能需要先更新scipy,因为它会给我带来问题。