简体   繁体   English

执行困惑度函数评估LDA模型时出错

[英]Getting an error while executing perplexity function to evaluate the LDA model

I am trying to evaluate the topic modeling(LDA). 我正在尝试评估主题建模(LDA)。 Getting a error while execting perplexity function as: Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'perplexity' for signature '"LDA_Gibbs", "numeric"' someone please help to solve this. 执行困惑性函数时遇到错误,例如:错误(函数(类,fdef,mtable):无法为签名“ LDA_Gibbs”,“数字”找到函数“困惑性”的继承方法,请帮助解决此问题。

As you haven't provided any example of your code, it's difficult to know what your exact issue is. 由于您未提供任何代码示例,因此很难知道确切的问题是什么。 However, I found this question when I was facing the same error so I will provide the problem I faced and solution here in the hope that it may help someone else. 但是,当我遇到相同的错误时,我发现了这个问题,因此我将在此提供我遇到的问题和解决方案,以希望它可以对其他人有所帮助。

In the topicmodels package, when fitting using Gibbs the perplexity() function requires newdata to be supplied in a document-term format. topicmodels包,配件在使用吉布斯的perplexity()函数需要newdata在文档术语格式来提供。 If you give it something else, you get this error. 如果您给它其他东西,则会出现此错误。 Going by your error message you were probably giving it something numeric instead of a dtm. 根据您的错误消息,您可能会给它一些numeric而不是dtm。

Here is a working example, using the newsgroups data from the lda package converted to the dtm format: 这是一个工作示例,使用来自lda包的新闻组数据转换为dtm格式:

library(topicmodels)

# load the required data from lda package
data("newsgroup.train.documents", "newsgroup.test.documents", "newsgroup.vocab", package="lda")


# create document-term matrix using newsgroups training data
dtm <- ldaformat2dtm(documents = newsgroup.train.documents, vocab = newsgroup.vocab)

# fit LDA model using Gibbs sampler
fit <- LDA(x = dtm, k = 20, method="Gibbs")

# create document-term matrix using newsgroups test data
testdtm <- ldaformat2dtm(documents = newsgroup.test.documents, vocab = newsgroup.vocab)

# calculate perplexity
perplexity(fit, newdata = testdtm)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LDA主题模型问题 - LDA Topic Model Issue SAP HANA:执行文本挖掘功能时SQL语法错误 - SAP HANA: sql syntax error while executing text mining function 如何在 LDA model 中为主题建模指定 random_state - how to specify random_state in LDA model for topic modelling 如何使用主题模型(LDA)输出来匹配和检索新的相同主题的文档 - How to use Topic Model (LDA) output to match and retrieve new, same-topic documents 将函数分配给字典值时出错 - Error while assigning function to the values of a dictionary 在Knime中为文本分析创建工作流程时出错 - Getting error while creating workflow in Knime for text analytics 没有空文档时,DocumentTermMatrix / LDA会产生非零输入错误 - DocumentTermMatrix /LDA produces non-zero entry error when there is no empty documents 结合 wdSeparateByTabs 和 wdSeparateByDefaultListSeparator= "|" 在执行 ConvertTblsToText() - Combine wdSeparateByTabs and wdSeparateByDefaultListSeparator= "|" while executing ConvertTblsToText() 导入错误:使用基于 QRNN 的预训练语言模型时没有名为“forget_mult_cuda”的模块错误 - ImportError: No module named 'forget_mult_cuda' error while using QRNN based pretrained Language model 在 R 中的文本 Package 中使用 textEmbed() function 时出现手电筒错误 - I am getting a Torch error when using the textEmbed() function in the Text Package in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM