【问题标题】:Error: attempt to apply non-function for sparklyr ml_lda ml_describe_topics错误:尝试为 sparklyr ml_lda ml_describe_topics 应用非功能
【发布时间】:2020-05-27 08:27:50
【问题描述】:

我正在尝试使用 sparklyr 运行 LDA 模型。文档建议我可以在我的模型上使用函数 ml_describe_topics 来为每个主题提取最相关的单词,但是当我运行它时会出现错误。

我的代码示例如下:

library(sparklyr)
library(magrittr)
library(dplyr)

    lda_model <- input_text %>%
      ft_tokenizer(input_col = "text_data", output_col = "word_tokens") %>%
      mutate(all_words = explode(word_tokens)) %>%
      ml_lda(~all_words, k = 3, max_iter = 100)

    lda_model %>% ml_describe_topics

我收到以下错误:

Error in model$describe_topics(max_terms_per_topic) :  Error in model$describe_topics(max_terms_per_topic) : 
  attempt to apply non-function
Error in model$describe_topics(max_terms_per_topic) : 
  attempt to apply non-function
In addition: Warning message:
In do.call(.f, args, envir = .env) :
  'what' must be a function or character string

谁能解释这里出了什么问题?我很困惑为什么该功能对我不起作用,尤其是当它遵循我可以找到的文档中的示例时。

【问题讨论】:

    标签: r machine-learning topic-modeling sparklyr


    【解决方案1】:

    我也遇到了这个错误。 对我来说,问题是 ml_lda() 返回了 pipeline_model 而不是模型本身。该模型是该结构的一部分。这在文档中不是很清楚。

    ldamodel$model 调用函数会得到想要的结果:

    ml_describe_topics(ldamodel$model) -->

    # Source: spark<?> [?? x 3]
       topic termIndices termWeights
       <int> <list>      <list>     
     1     0 <int [10]>  <dbl [10]> 
     2     1 <int [10]>  <dbl [10]> 
     3     2 <int [10]>  <dbl [10]> 
    (...)
    

    【讨论】:

      猜你喜欢
      • 2013-04-27
      • 1970-01-01
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      • 2018-10-22
      • 2018-10-09
      相关资源
      最近更新 更多