2017-11-16 9 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) 

これは、オートグレーダーの罰金を通過します。 :しかし、単に私もドキュメントから文を参照してください

gensim.interfaces.TransformedCorpus

を返し

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)) 

この:次のタスクは、私は次のように行うことをしようとする新しいドキュメントのトピック分布を見つけることです"あなたは>>> 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] 
関連する問題