如何找到 lda 的最佳度量

How to find the best measures for lda

使用 quanteda 包中的 example for lda

require(quanteda)
require(quanteda.corpora)
require(lubridate)
require(topicmodels)
corp_news <- download('data_corpus_guardian')
corp_news_subset <- corpus_subset(corp_news, 'date' >= 2016)
ndoc(corp_news_subset)
dfmat_news <- dfm(corp_news, remove_punct = TRUE, remove = stopwords('en')) %>% 
    dfm_remove(c('*-time', '*-timeUpdated', 'GMT', 'BST')) %>% 
    dfm_trim(min_termfreq = 0.95, termfreq_type = "quantile", 
             max_docfreq = 0.1, docfreq_type = "prop")

dfmat_news <- dfmat_news[ntoken(dfmat_news) > 0,]
dtm <- convert(dfmat_news, to = "topicmodels")
lda <- LDA(dtm, k = 10)

是否有任何指标可以帮助理解适当数量的主题?我需要这个,因为我的文本很小,不知道性能是否正确。还有什么方法可以有一个性能度量(即precision/recall)来衡量具有不同特征的lda的更好性能?

您可以使用多种拟合优度 (GoF) 指标来评估 LDA 模型。最常见的称为困惑度,您可以通过包 topicmodels 中的函数 perplexity() 来计算它。 select 最佳模型的方法是在图中寻找 "knee"。这个想法源于无监督方法,是 运行 具有不同主题的多个 LDA 模型。随着主题数量的增加,您应该会看到困惑度降低。当你发现膝盖或增量减少可以忽略不计时,你想停止。当您 运行 主成分分析时细化碎石图。

话虽如此,有一个名为 ldatuning which implements four additional metrics based on density-based clustering and on Kullback-Leibler divergence. Three of them can be used with both VEM and Gibbs inference, while the method by Griffith 的 R 包只能与 Gibbs 一起使用。对于其中一些指标,您寻找最小值,对于其他指标,您寻找最大值。此外,您始终可以计算想要最大化的模型的对数似然。从 LDA 对象中提取可能性的方法非常简单。假设您有一个名为 ldamodel:

的 LDA 模型
loglikelihood = as.numeric(logLik(ldamodel))

围绕这个主题有很多研究。例如,您可以查看这些论文:

另外,你可以看看我和我的一个同事正在研究的一篇论文的预印本,这篇论文使用简单的参数测试来评估 GoF。我们还开发了一个 R 包,可用于 class LDA 来自 topicmodels 的 LDA 模型列表。你可以找到论文here and the package here。非常欢迎您提交您可能在包中发现的任何问题。该论文目前正在审阅中,但再次欢迎您提出意见。

希望这对您有所帮助!