我正在使用 R 中的tm
andlda
包来对新闻文章语料库进行主题建模。但是,我遇到了一个“非字符”问题,因为""
这会弄乱我的主题。这是我的工作流程:
text <- Corpus(VectorSource(d$text))
newtext <- lapply(text, tolower)
sw <- c(stopwords("english"), "ahram", "online", "egypt", "egypts", "egyptian")
newtext <- lapply(newtext, function(x) removePunctuation(x))
newtext <- lapply(newtext, function(x) removeWords(x, sw))
newtext <- lapply(newtext, function(x) removeNumbers(x))
newtext <- lapply(newtext, function(x) stripWhitespace(x))
d$processed <- unlist(newtext)
corpus <- lexicalize(d$processed)
k <- 40
result <-lda.collapsed.gibbs.sampler(corpus$documents, k, corpus$vocab, 500, .02, .05,
compute.log.likelihood = TRUE, trace = 2L)
不幸的是,当我训练 lda 模型时,除了最常出现的单词是“”之外,一切看起来都很好。我尝试通过从下面给出的词汇中删除它并重新估计上面的模型来解决这个问题:
newtext <- lapply(newtext, function(x) removeWords(x, ""))
但是,它仍然存在,如下所示:
str_split(newtext[[1]], " ")
[[1]]
[1] "" "body" "mohamed" "hassan"
[5] "cook" "found" "turkish" "search"
[9] "rescue" "teams" "rescued" "hospital"
[13] "rescue" "teams" "continued" "search"
[17] "missing" "body" "cook" "crew"
[21] "wereegyptians" "sudanese" "syrians" "hassan"
[25] "cook" "cargo" "ship" "sea"
[29] "bright" "crashed" "thursday" "port"
[33] "antalya" "southern" "turkey" "vessel"
[37] "collided" "rocks" "port" "thursday"
[41] "night" "result" "heavy" "winds"
[45] "waves" "crew" ""
关于如何删除它的任何建议?添加""
到我的停用词列表中也无济于事。