2016-10-11 14 views
6

LDAを使用して各ドキュメントを1つのトピックに割り当てたいと考えています。今私は、あなたが得るものはLDAからの話題の分布であることを理解しています。しかし、下の最後の行から分かるように、私はそれを最も可能性の高いトピックに割り当てます。Gensim LDAトピックの割り当て

私の質問はこれです。私はlda[corpus]をやや2回実行して、これらのトピックを得る必要があります。私にこのトピック割り当てベクトルを直接与える他の組み込みgensim関数がありますか?特にLDAアルゴリズムは文書を通過しているので、これらのトピック割り当てを保存している可能性があります。

# Get the Dictionary and BoW of the corpus after some stemming/ cleansing 
texts = [[stem(word) for word in document.split() if word not in STOPWORDS] for document in cleanDF.text.values] 
dictionary = corpora.Dictionary(texts) 
dictionary.filter_extremes(no_below=5, no_above=0.9) 
corpus = [dictionary.doc2bow(text) for text in texts] 

# The actual LDA component 
lda = models.LdaMulticore(corpus=corpus, id2word=dictionary, num_topics=30, chunksize=10000, passes=10,workers=4) 

# Assign each document to most prevalent document 
lda_topic_assignment = [max(p,key=lambda item: item[1]) for p in lda[corpus]] 

答えて

-1
dictionary = corpora.Dictionary(texts) 
corpus = [dictionary.doc2bow(text) for text in texts] 


test =LDA[corpus[0]] 
print(test) 
sorted(test, reverse=True, key=lambda x: x[1]) 

Topics = ['Topic_'+str(sorted(LDA[i], reverse=True, key=lambda x: x[1])[0][0]).zfill(3) for i in corpus] 
+4

あなたのソリューションが正しい理由を説明するいくつかのコンテキストを提供してください。これは、OPがそれを理解するのに役立ちます。 –

関連する問題