SparkNLP要求失败

时间:2018-03-21 11:18:11

标签: apache-spark nlp bigdata apache-spark-mllib pipeline

我正在尝试在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).

我的Pipelin是

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

1 个答案:

答案 0 :(得分:0)

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

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

如果没有定义outputCols,则输出列默认为“finished _ $ {inputColumn}”。

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

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

相关问题