上下文
提前谢谢你的帮助。现在,我已经通过Jonathan的“LDA”包中的lda函数运行了一个数据集(注:这与“主题模型”包不同)。下面是一个可复制的示例,它使用在安装和加载'lda‘包时自动出现的cora数据集。
library(lda)
data(cora.documents) #list of words contained in each of the 2,410 documents
data(cora.vocab) #vocabulary list of words that occur at least once across all documents
然后,通过设置不
我对主题建模/潜在Dirichlet分配很陌生,很难理解如何将这个概念应用于我的数据集(或者它是否是正确的方法)。
我有少量的文学文本(小说),并想提取一些一般性的话题使用LDA。
我正在使用Python中的gensim模块以及一些nltk特性。在一次测试中,我把原来的课文(只有6篇)分成30块,每篇有1000个单词。然后,我将块转换成文档项矩阵,并运行算法。这是代码(虽然我认为这与问题无关):
# chunks is a 30x1000 words matrix
dictionary = gensim.corpora.dictionary.Dictionary(chunks)
corpus
我使用python gensim从231个句子的小语料库中训练一个潜在的Dirichlet分配(LDA)模型。然而,每次我重复这个过程,都会产生不同的主题。
为什么每次都使用相同的LDA参数和语料库生成不同的主题?
和如何稳定主题生成?
我正在使用这个语料库()和这个停止词列表(),下面是我的代码:
from gensim import corpora, models, similarities
from gensim.models import hdpmodel, ldamodel
from itertools import izip
from collections import defa
作为参考,我已经研究了以下问题:
我希望我的LDA模型训练从Gensim分类一个句子下的主题之一,模型创建。长队的东西
lda = models.LdaModel(corpus=corpus, id2word=id2word, num_topics=7, passes=20)
lda.print_topics()
for line in document: # where each line in the document is its own sentence for simplicity
print('Sentence: ', line)
topic =
我使用Gensim包进行主题建模。这个想法是为了理解flickr标签中的主题是什么。到目前为止,我使用的是这个代码(文档是标签):
texts = [[word for word in document.split(";") if word not in stoplist] for document in documents]
dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]
lda = ldamodel.Lda
我希望将交叉验证应用于LDA算法,以确定主题的数量(K)。我的疑问是关于评估者,因为我希望使用对数似然。我应该在.setEvaluator上设置什么(?)创建交叉验证时?
// Define a simple LDA
val lda = new LDA()
.setMaxIter(10)
.setFeaturesCol("features")
// We use a ParamGridBuilder to construct a grid of parameters to search over.
val range = 1 to 20
val paramGrid =