Ryan Erwin
Ryan Erwin

Reputation: 817

LdaModel - random_state parameter not recognized - gensim

I'm using gensim's LdaModel, which, according to the documentation, has the parameter random_state. However, I'm getting an error that says:

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

Without the random_state parameter, the function works as expected. So, the workflow looks like this for those that want to know what else is happening...

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

Which results in the error message above...

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

I'd like to be able to recreate my results, if possible.

Upvotes: 0

Views: 1612

Answers (1)

user2285236
user2285236

Reputation:

According to this, random_state parameter was added in the latest version (0.13.2). You can update your gensim installation with pip install gensim --upgrade. You might need to update scipy first, because it caused me problems.

Upvotes: 1

Related Questions