SparkNLP 要求失败

SparkNLP requirement Failed

我正在尝试 运行 在 spark 2.3 上统一 SparkNLP 和 MLlib 管道,但是当我在上面安装数据集时出现错误。

val pipelineModel = pipeline.fit(descfeature)

以下是错误的:-

 requirement failed: Input type must be string type but 
 gotArrayType(StructType(StructField(annotatorType,StringType,true), 
 StructField(start,IntegerType,false), 
 StructField(end,IntegerType,false), 
 StructField(result,StringType,true), 
StructField(metadata,MapType(StringType,StringType,true),true)),true).

我的流水线是

val pipeline = new Pipeline()
  .setStages(Array(documentAssembler,tokenizer,stemmer,stopWordsRemover,vectorizer,lda))

stopWordRemover 不适用于注释,但适用于字符串。对于注解值到字符串的转换,需要在stemmer和stopWordRemover之间添加一个finisher:

val finisher = new Finisher()
    .setInputCols("filtered")
    .setOutputCols("filtered")
    .setOutputAsArray(true)

如果没有定义 outputCols,输出列默认为 "finished_${inputColumn}"。

由于 stopwordRemover 需要一个字符串数组,因此您需要激活选项 setOutputAsArray。

在 Spark NLP 页面上更详细地解释了 Finisher:http://nlp.johnsnowlabs.com/components.html