我无法使用 text2vec 为我的测试数据创建 tf-idf 矩阵

I can't create tf-idf matrix for my test data using text2vec

我正在关注 this tutorial 并按照我做训练集的方式去做,但它一直在说同样的话。有人知道这有什么问题吗?

> #Construct sample document-term matrix con el vectorizer inicial
> sample.it <- itoken(rawsample$Abstract, 
+                     preprocessor = prep_fun, 
+                     tokenizer = tok_fun, 
+                     ids = rawsample$id,
+                     progressbar = F) 
> sample.dtm <- create_dtm (sample.it, vectorizer, vtype = "dgTMatrix", progressbar = FALSE)
> sample.tfidf <- TfIdf$new() #define tfidf model
> sample.tfidf <- fit_transform(sample.dtm, tfidf)
Error in fit_transform.Matrix(sample.dtm, tfidf) : 
  inherits(model, "mlapiTransformation") is not TRUE
> sample.tfidf  = create_dtm(sample.it, vectorizer, vtype = "dgTMatrix", progressbar = FALSE) %>% 
+   transform(tfidf)
Error in transform.Matrix(., tfidf) : 
  inherits(model, "mlapiTransformation") is not TRUE

sample.tfidf <- TfIdf$new() #define tfidf model
sample.tfidf <- fit_transform(sample.dtm, tfidf)

你在哪里定义tfidf?可能你需要这样的东西:

model =  TfIdf$new() #define tfidf model
sample.tfidf = fit_transform(sample.dtm, model)