无法让 tm

编程入门 行业动态 更新时间:2024-10-28 05:27:06
本文介绍了无法让 tm_map 使用 mc.cores 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个包含超过 1000 万个文档的大型语料库.每当我尝试使用 mc.cores 参数对多个内核进行转换时,我都会收到错误:

I have a large corpus with over 10M documents. Whenever I try a transformation over multiple cores using mc.cores argument I get error:

Error in FUN(content(x), ...) : unused argument (mc.cores = 10)

我目前托管的 r 工作室中有 15 个可用内核.

I have 15 available cores in my current hosted r studio.

# I have a corpus
> inspect(corpus[1])
<<VCorpus>>
Metadata:  corpus specific: 0, document level (indexed): 0
Content:  documents: 1

[[1]]
<<PlainTextDocument>>
Metadata:  7
Content:  chars: 46

> length(corpus)
[1] 10255313

观察当我尝试使用 tm_map 进行转换时会发生什么

Watch what happens when I try to make transformations using tm_map

library(tidyverse)
library(qdap)
library(stringr)
library(tm)
library(textstem)
library(stringi)
library(SnowballC)

例如

> corpus <- tm_map(corpus, content_transformer(replace_abbreviation), mc.cores = 10)
Error in FUN(content(x), ...) : unused argument (mc.cores = 10)

尝试添加 lazy = T

Tried adding lazy = T

corpus <- tm_map(corpus, content_transformer(replace_abbreviation), mc.cores = 10, lazy = T) # read the documentation, still don't really get what this does

转换后如果我去例如

> corpus[[1]][1] I get:
Error in FUN(content(x), ...) : unused argument (mc.cores = 10)

而在我得到之前:

> corpus.beforetransformation[[1]][1]
$content
[1] "here is some text"

我在这里做错了什么?如何使用 mc.cores 参数来使用更多处理器?

What am I doing wrong here? How can I use mc.cores argument to use more of my processors?

可重现的例子:

sometext <- c("cats dogs rabbits", "oranges banannas pears", "summer fall winter") %>% 
  data.frame(stringsAsFactors = F) %>% DataframeSource %>% VCorpus

corpus.example <- tm_map(sometext, content_transformer(replace_abbreviation), mc.cores = 2, lazy = T)
corpus.example[[1]][1]

推荐答案

来自 tm 文档,请尝试以下操作:

From the tm documentation, try the following:

options(mc.cores = 10)  # or whatever
tm_parLapply_engine(parallel::mclapply)  # mclapply gets the number of cores from global options
tm_map(sometext, content_transformer(replace_abbreviation))

这篇关于无法让 tm_map 使用 mc.cores 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 05:18:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390252.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:tm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!