gpt4 book ai didi

r - 尝试从 DocumentTermMatrix 中删除单词以使用主题模型

转载 作者:行者123 更新时间:2023-12-04 21:58:26 25 4
gpt4 key购买 nike

所以,我正在尝试使用 topicmodelsR (大约 6400 个文档的语料库中的 100 个主题,每个文档大约 1000 个单词)。该进程运行然后死亡,我认为是因为它的内存不足。

所以我尝试缩小 lda() 的文档术语矩阵的大小函数作为输入;我想我可以使用 minDocFreq 做到这一点生成文档术语矩阵时的函数。但是当我使用它时,它似乎没有任何区别。这是一些代码:

这是相关的代码:

> corpus <- Corpus(DirSource('./chunks/'),fileEncoding='utf-8')
> dtm <- DocumentTermMatrix(corpus)
> dim(dtm)
[1] 6423 4163
# So, I assume this next command will make my document term matrix smaller, i.e.
# fewer columns. I've chosen a larger number, 100, to illustrate the point.
> smaller <- DocumentTermMatrix(corpus, control=list(minDocFreq=100))
> dim(smaller)
[1] 6423 41613

相同的维度和相同的列数(即相同的项数)。

知道我做错了什么吗?谢谢。

最佳答案

您的问题的答案在这里:https://stackoverflow.com/a/13370840/1036500 (给它一个upvote!)

简而言之,tm 的更新版本包不包括minDocFreq而是使用 bounds ,例如,您的

smaller <- DocumentTermMatrix(corpus, control=list(minDocFreq=100))

现在应该是
require(tm)
data("crude")

smaller <- DocumentTermMatrix(crude, control=list(bounds = list(global = c(5,Inf))))
dim(smaller) # after Terms that appear in <5 documents are discarded
[1] 20 67
smaller <- DocumentTermMatrix(crude, control=list(bounds = list(global = c(10,Inf))))
dim(smaller) # after Terms that appear in <10 documents are discarded
[1] 20 17

关于r - 尝试从 DocumentTermMatrix 中删除单词以使用主题模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16287546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com