2017-11-16 22 views
0

훈련 :주제 distristribution 나는 이런 식으로 뭔가의 할당이 countvectorizer

import gensim 
from sklearn.feature_extraction.text import CountVectorizer 

newsgroup_data = ["Human machine interface for lab abc computer applications", 
      "A survey of user opinion of computer system response time", 
       "The EPS user interface management system", 
       "System and human system engineering testing of EPS", 
       "Relation of user perceived response time to error measurement", 
       "The generation of random binary unordered trees", 
       "The intersection graph of paths in trees", 
       "Graph minors IV Widths of trees and well quasi ordering", 
       "Graph minors A survey"] 

vect = CountVectorizer(stop_words='english', 
         token_pattern='(?u)\\b\\w\\w\\w+\\b') 
X = vect.fit_transform(newsgroup_data) 
corpus = gensim.matutils.Sparse2Corpus(X, documents_columns=False) 
id_map = dict((v, k) for k, v in vect.vocabulary_.items()) 

내 작업은 코퍼스에 LDA 모델 매개 변수를 추정 10 개 항목의 목록과 가장 중요한을 찾을 수 있습니다 각 주제의 10 단어는 다음과 같습니다.

top10 = ldamodel.print_topics(num_topics=10, num_words=10) 
ldamodel = gensim.models.ldamodel.LdaModel(corpus=corpus, 
       id2word=id_map, num_topics=10, minimum_probability=0) 

자동 기록기가 정상적으로 전달됩니다.

new_doc = ["\n\nIt's my understanding that the freezing will start to occur because \ 
of the\ngrowing distance of Pluto and Charon from the Sun, due to it's\nelliptical orbit. \ 
It is not due to shadowing effects. \n\n\nPluto can shadow Charon, and vice-versa.\n\nGeorge \ 
Krumins\n-- "] 
newX = vect.transform(new_doc) 
newC = gensim.matutils.Sparse2Corpus(newX, documents_columns=False) 
print(ldamodel.get_document_topics(newC)) 

이 그러나 단순히

gensim.interfaces.TransformedCorpus

나는 또한 문서 문에서 참조를 반환 : 다음 작업은 다음과 같이 내가하려고 새로운 문서의 주제 분포를 찾을 수 있습니다 : "그런 다음 >>> doc_lda = lda [doc_bow]를 사용하여 보이지 않는 새 문서에 대한 주제 분포를 추측 할 수 있지만 여기에도 성공하지 못했습니다. 어떤 도움을 주셔서 감사합니다.

답변

0

특히 인터페이스 gensim.interfaces.TransformedCorpus에 대해 자세히 알아보기. 내가 이해하는 바와 같이 인터페이스는 내가 요청한 주제/배포판을 가리키고 있지만 값을보기 위해 반복해야한다.

topic_dist = ldamodel.get_document_topics(newC) 
td=[] 
for topic in topic_dis: 
    td.append(topic) 
td = td[0] 

트릭을 수행합니다. 사용할 수도 있습니다

topic_dist = ldamodel[newC]