sac*_*ruk 8 python lda gensim topic-modeling
我希望使用LDA将每个文档分配给一个主题.现在我意识到你得到的是LDA主题的分布.但是,正如您从下面的最后一行所看到的,我将其分配给最可能的主题.
我的问题是这个.lda[corpus]为了得到这些话题,我必须第二次跑步.是否有一些其他内置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 topic
lda_topic_assignment = [max(p,key=lambda item: item[1]) for p in lda[corpus]]
Run Code Online (Sandbox Code Playgroud)
没有其他内置 Gensim 函数可以直接给出主题分配向量。
您的问题是有效的,LDA 算法已经通过了文档,但 LDA 的实现是通过分块更新模型(基于参数值chunksize)来工作的,因此它不会将整个语料库保留在内存中。
因此你必须使用lda[corpus]或使用该方法lda.get_document_topics()
| 归档时间: |
|
| 查看次数: |
997 次 |
| 最近记录: |