2016-09-02 5 views
0

나는 에 따라 random_state을 갖는 gensimLdaModel을 사용하고 있습니다. 그러나, 나는라는 오류 받고 있어요 : 예상대로 random_state 매개 변수가 없으면LdaModel - random_state 매개 변수가 인식되지 않음 - gensim

TypeError: __init__() got an unexpected keyword argument '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

this에 따르면 random_state 매개 변수는 최신 버전 (0.13.2)에 추가되었습니다. gensim 설치를 pip install gensim --upgrade으로 업데이트 할 수 있습니다. 문제가 발생하여 scipy을 먼저 업데이트해야 할 수 있습니다.