且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将标记列表转换为 n-gram

更新时间:2023-11-23 14:03:58

这是 embed 的一种方式.

find_ngrams <- function(x, n) {
    if (n == 1) return(x)
    c(x, apply(embed(x, n), 1, function(row) paste(rev(row), collapse=' ')))
}

您的函数中似乎存在错误.如果你解决了这个问题,我们可以做一个基准测试.

There seems to be a bug in your function. If you fix that, we can do a benchmark.