R:text2vec DTM 的文档编号与原始文档编号不正确
R : text2vec DTM's document number is not correct with origin document number
我是一个经常使用text2vec的学生
直到去年,我一直在使用这个程序,没有任何问题。
但是今天当我使用Parallel函数构建DTM时,DTM的文档编号与原始文档编号不正确。
DTM的文档数与原始文档数除以注册核心相匹配。所以怀疑是并行处理后结果没有合并
附上我测试过的代码。
library(stringr)
library(text2vec)
library(data.table)
library (parallel)
library (doParallel)
N <- detectCores()
cl <- makeCluster (N)
registerDoParallel (cl)
data("movie_review")
setDT(movie_review)
setkey(movie_review, id)
##number of document is 5000
IT <- itoken_parallel (movie_review$review,
ids = movie_review$id,
tokenizer = word_tokenizer,
progressbar = F)
VOCAB <- create_vocabulary (
IT,
ngram = c(1, 1)) %>%
prune_vocabulary (term_count_min = 3)
VoCAB.order <- VOCAB[order((VOCAB$term_count), decreasing = T),]
VECTORIZER <- vocab_vectorizer (VOCAB)
DTM <- create_dtm (IT,
VECTORIZER,
distributed = F)
##DTM dimension is not 5000. number is 5000/4(number of Cores) = 1250
dim(DTM)
我检查了 Vignette 中的 text2vec itoken 函数。我在itoken中找到了测试并行处理的例子,处理的很好,没有报错。
在这个过程中,如何使用停用词和最小频率功能?
N_WORKERS = 1 # change 1 to number of cores in parallel backend
if(require(doParallel)) registerDoParallel(N_WORKERS)
data("movie_review")
it = itoken_parallel(movie_review$review[1:100], n_chunks = N_WORKERS)
system.time(dtm <- create_dtm(it, hash_vectorizer(2**16), type = 'dgTMatrix'))
期待真诚的回答
感谢您的关注。
我是一个经常使用text2vec的学生
直到去年,我一直在使用这个程序,没有任何问题。
但是今天当我使用Parallel函数构建DTM时,DTM的文档编号与原始文档编号不正确。
DTM的文档数与原始文档数除以注册核心相匹配。所以怀疑是并行处理后结果没有合并
附上我测试过的代码。
library(stringr)
library(text2vec)
library(data.table)
library (parallel)
library (doParallel)
N <- detectCores()
cl <- makeCluster (N)
registerDoParallel (cl)
data("movie_review")
setDT(movie_review)
setkey(movie_review, id)
##number of document is 5000
IT <- itoken_parallel (movie_review$review,
ids = movie_review$id,
tokenizer = word_tokenizer,
progressbar = F)
VOCAB <- create_vocabulary (
IT,
ngram = c(1, 1)) %>%
prune_vocabulary (term_count_min = 3)
VoCAB.order <- VOCAB[order((VOCAB$term_count), decreasing = T),]
VECTORIZER <- vocab_vectorizer (VOCAB)
DTM <- create_dtm (IT,
VECTORIZER,
distributed = F)
##DTM dimension is not 5000. number is 5000/4(number of Cores) = 1250
dim(DTM)
我检查了 Vignette 中的 text2vec itoken 函数。我在itoken中找到了测试并行处理的例子,处理的很好,没有报错。
在这个过程中,如何使用停用词和最小频率功能?
N_WORKERS = 1 # change 1 to number of cores in parallel backend
if(require(doParallel)) registerDoParallel(N_WORKERS)
data("movie_review")
it = itoken_parallel(movie_review$review[1:100], n_chunks = N_WORKERS)
system.time(dtm <- create_dtm(it, hash_vectorizer(2**16), type = 'dgTMatrix'))
期待真诚的回答
感谢您的关注。