2017-03-25 11 views
0

LDA 모델을 훈련 할 수 없습니다, 나는 그것에서 말뭉치 만들기 위해 tutorial의 지침을 따르Gensim : 나는 문장의 목록을 가지고

texts = [[word for word in document.lower().split() if word.isalpha()] for document in documents] 
corpus = corpora.Dictionary(texts) 

내가이 말뭉치에 LDA 모델을 훈련 할을 주제 키워드를 추출하십시오.

lda = models.LdaModel(corpus, num_topics=10) 

그러나 훈련 중 오류가 발생합니다 : TypeError: 'int' object is not iterable. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 코퍼스의 형식은 무엇이되어야합니까?

답변

-1

말뭉치를 한 후에는 ('hashing trick' 소위) 단어에서 해시를 만드는 doc2bow 단일 코퍼스해야한다 :

texts = [[word for word in document.lower().split() if word.isalpha()] for document in documents] 
corpus = corpora.Dictionary(texts) 
hashed_corpus = [corpora.doc2bow(text) for text in texts] 

을 그리고 그 후 당신은 hashed_corpus하여 모델을 학습 할 수 있습니다

lda = models.LdaModel(corpus, id2word=corpus, num_topics=5) 

id2word은 해시에서 단어로 주제를 매핑하고 숫자를 사용하지 않고 단어로 주제를 가져올 수 있습니다.