Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R stm-提供的文本数和建模的文档数不匹配_R_Text Mining_Topic Modeling - Fatal编程技术网

R stm-提供的文本数和建模的文档数不匹配

R stm-提供的文本数和建模的文档数不匹配,r,text-mining,topic-modeling,R,Text Mining,Topic Modeling,在构建自己的词典(用于监督分析)之前,我正在使用摘要中的文本数据,并尝试使用stm(结构化主题建模)来查看非监督提取的主题。 我正在处理一个问题,我想知道以前是否有人遇到过同样的问题。 运行findThoughts()时,出现以下错误: findThoughts中出错(out.stm,topics=27,text=corpus$documents$text,: 提供的文本数量和建模的文档数量不匹配 我不确定我的数据出了什么问题。我认为这可能与语料库中没有摘要的空行中的NA值有关,但删除NA行后也

在构建自己的词典(用于监督分析)之前,我正在使用摘要中的文本数据,并尝试使用stm(结构化主题建模)来查看非监督提取的主题。 我正在处理一个问题,我想知道以前是否有人遇到过同样的问题。 运行
findThoughts()
时,出现以下错误:

findThoughts中出错(out.stm,topics=27,text=corpus$documents$text,: 提供的文本数量和建模的文档数量不匹配

我不确定我的数据出了什么问题。我认为这可能与语料库中没有摘要的空行中的
NA
值有关,但删除
NA
行后也会发生同样的情况(如下所示:

df[!is.na(df$abstract),]

如果您对此有任何想法,请告诉我。

当长度(text)!=out.stm的行数时,findThoughts函数返回错误“提供的文本数和建模的文档数不匹配”

这是一个错误,源于调用“stm”函数之前用于处理文档的textProcessor函数

这就是为什么会发生这种情况: 临时输出具有一个属性temp$docs.removed,该属性列出了已删除的行。因此,“temp$documents”的长度将小于“comments”乘以temp$docs.removed的长度

z<-comments[-temp$docs.removed,]
length(z)

thoughts3 <- findThoughts(a,texts=z,topics=3, n=10,thresh=0.0)
因此,使用temp$documents建模的stm对象“a”和$theta(文档主题概率矩阵)将与temp$documents具有相同的长度

temp<-textProcessor(comments, metadata=NULL,  lowercase=TRUE, removestopwords=TRUE, removenumbers=TRUE,  removepunctuation=TRUE, stem=TRUE, wordLengths=c(3,Inf),  sparselevel=1, language="en",  verbose=TRUE, onlycharacter= FALSE, striphtml=FALSE, customstopwords=NULL, onlytxtfiles=TRUE)


meta<-temp$meta
vocab<-temp$vocab
docs<-temp$documents
a<-stm(documents=docs, vocab=vocab, K=7,data=meta, max.em.its=800)

temp当长度(text)!=out.stm的行数时,findThoughts函数返回错误“提供的文本数和建模的文档数不匹配”

这是一个错误,源于调用“stm”函数之前用于处理文档的textProcessor函数

这就是为什么会发生这种情况: 临时输出具有一个属性temp$docs.removed,该属性列出了已删除的行。因此,“temp$documents”的长度将小于“comments”乘以temp$docs.removed的长度

z<-comments[-temp$docs.removed,]
length(z)

thoughts3 <- findThoughts(a,texts=z,topics=3, n=10,thresh=0.0)
因此,使用temp$documents建模的stm对象“a”和$theta(文档主题概率矩阵)将与temp$documents具有相同的长度

temp<-textProcessor(comments, metadata=NULL,  lowercase=TRUE, removestopwords=TRUE, removenumbers=TRUE,  removepunctuation=TRUE, stem=TRUE, wordLengths=c(3,Inf),  sparselevel=1, language="en",  verbose=TRUE, onlycharacter= FALSE, striphtml=FALSE, customstopwords=NULL, onlytxtfiles=TRUE)


meta<-temp$meta
vocab<-temp$vocab
docs<-temp$documents
a<-stm(documents=docs, vocab=vocab, K=7,data=meta, max.em.its=800)

temp根据Sruthi Susan Thomas给出的答案,适合我的正确代码是将“out”输入(out=prepDocuments(text$documents,text$vocab,text$meta))改为“temp”根据Sruthi Susan Thomas给出的答案,我的正确代码是用“Out”输入(Out=prepDocuments(text$documents,text$vocab,text$meta))代替“temp”在参数中。Out删除文档的正确索引