【问题标题】:Why is DocumentTermMatrix running out of memory when plenty left?为什么 DocumentTermMatrix 内存不够用?
【发布时间】:2015-07-16 16:44:44
【问题描述】:

我在尝试从 tm 包运行 DocumentTermMatrix 时遇到以下内存分配错误。不知道为什么会这样,因为我的机器有 128 gigs 的内存,而语料库只有 3 gigs。

Error in mcfork() :
  unable to fork, possible reason: Cannot allocate memory
Calls: DocumentTermMatrix ... content.VCorpus -> materialize -> mclapply -> lapply -> FUN -> mcfork

这就是被调用的全部内容:

library(tm)
text <- read.csv('/path/to/text.csv', ...)

vct <- VCorpus(VectorSournce(text[,2]))
vct <- tm_map(vct, removeWords, stopwords("english"), mc.cores=1)
dtm <- DocumentTermMatrix(vct)

【问题讨论】:

    标签: r tm


    【解决方案1】:

    this 的帖子中,我想出了如何通过限制使用的核心数量来解决这个问题。由于DocumentTermMatrix 没有明确的选项,我不得不通过options 进行:

    num.cores <- getOption("mc.cores")
    options(mc.cores=1)
    dtm <- DocumentTermMatrix(vct)
    options(mc.cores=num.cores)
    

    【讨论】:

      猜你喜欢
      • 2017-05-26
      • 2019-11-18
      • 2014-04-24
      • 2023-03-19
      • 2020-12-06
      • 2014-10-13
      • 1970-01-01
      • 2019-08-20
      • 2019-01-30
      相关资源
      最近更新 更多