LdaModel - random_state 参数无法识别 - gensim
LdaModel - random_state parameter not recognized - gensim
我正在使用 gensim
的 LdaModel
,根据 documentation,它具有参数 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'
如果可能的话,我希望能够重现我的结果。
根据this,在最新版本(0.13.2)中添加了random_state
参数。您可以使用 pip install gensim --upgrade
更新您的 gensim 安装。您可能需要先更新 scipy
,因为它给我带来了问题。
我正在使用 gensim
的 LdaModel
,根据 documentation,它具有参数 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'
如果可能的话,我希望能够重现我的结果。
根据this,在最新版本(0.13.2)中添加了random_state
参数。您可以使用 pip install gensim --upgrade
更新您的 gensim 安装。您可能需要先更新 scipy
,因为它给我带来了问题。