gpt4 book ai didi

r - 如何在 r 中使用整洁的文本进行二元模型主题建模?

转载 作者:行者123 更新时间:2023-12-04 00:02:08 27 4
gpt4 key购买 nike

因此,我尝试使用 tidytext 包进行二元组主题建模,按照 tidytext 网站上的步骤进行操作:https://www.tidytextmining.com/ngrams.html

我能够到达“word_counts”部分,其中 R 计算每个二元词组的频率。

“word_counts”返回以下内容:

   customer_id       word          n
<chr> <chr> <int>
1 00000001234 sample text 45
2 00000002345 good morning 30
3 00000003456 happy friday 24

下一步是将上面的信息放入 dtm 格式

我的代码如下:

lda_dtm <- word_counts %>%
cast_dtm(customer_id, word, n)

发出警告消息:

Warning message:
Trying to compute distinct() for variables not found in the data:
- `row_col`, `column_col`
This is an error, but only a warning is raised for compatibility reasons.
The operation will return the input unchanged.

但是“lda_dtm”看起来格式正确。

lda_dtm
<<DocumentTermMatrix (documents: 9517, terms: 341545)>>
Non-/sparse entries: 773250/3249710515
Sparsity : 100%
Maximal term length: NA
Weighting : term frequency (tf)

但是,当我尝试运行 lda 时,它不起作用。

burnin <- 4000
iter <- 300
thin <- 500
seed <-list(2003,5,63,100001,765)
nstart <- 5
best <- TRUE
k <- 6

out_LDA <- LDA(lda_dtm,
k = k,
method="Gibbs",
control = list(nstart=nstart,
seed = seed,
best=best,
burnin = burnin,
iter = iter,
thin = thin))

提出了以下警告:

Error in seq.default(CONTROL_i@iter, control@burnin + control@iter, by = control@thin) : 
wrong sign in 'by' argument

我在整洁的文本网站上没有看到bi-grams的主题建模教程,该教程是专门针对unigrams的。我应该如何调整格式以使其与bi-grams一起使用?

最佳答案

1:你从cast_dtm得到的消息实际上来自cast_sparse。 github 上有两个问题 #120 和 #121 处理这个问题。目前,该问题已在 github 上的包中修复,但尚未发布。

如果你愿意,你可以从 github 安装它 devtools::install_github("juliasilge/tidytext") .

2:你从LDA得到的错误与1无关。如果你只是运行out_LDA <- LDA(lda_dtm, k = k) LDA 会运行得很好。问题出在你的控制选项 thin 。这应该小于或等于 iter 参数。在你的例子中,它设置为 500,而 iter 设置为 300。因此会出现错误。您可以看到当 Thin 比 iter 高 1 时出现错误。

关于r - 如何在 r 中使用整洁的文本进行二元模型主题建模?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51106727/

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