I'm using com.johnsnowlabs.nlp-2.2.2
with spark-2.4.4 to process some articles. In those articles, there are some very long words I'm not interested in and which slows down the POS tagging a lot.
I would to like to exclude them after the tokenization and before the POSTagging.
I tried to write the smaller code to reproduce my issues
import sc.implicits._
val documenter = new DocumentAssembler().setInputCol("text").setOutputCol("document").setIdCol("id")
val tokenizer = new Tokenizer().setInputCols(Array("document")).setOutputCol("token")
val normalizer = new Normalizer().setInputCols("token").setOutputCol("normalized").setLowercase(true)
val df = Seq("This is a very useless/ugly sentence").toDF("text")
val document = documenter.transform(df.withColumn("id", monotonically_increasing_id()))
val token = tokenizer.fit(document).transform(document)
val token_filtered = token
.drop("token")
.join(token
.select(col("id"), col("token"))
.withColumn("tmp", explode(col("token")))
.groupBy("id")
.agg(collect_list(col("tmp")).as("token")),
Seq("id"))
token_filtered.select($"token").show(false)
val normal = normalizer.fit(token_filtered).transform(token_filtered)
I have this error when I transform token_filtered
+--------------------+---+--------------------+--------------------+--------------------+
| text| id| document| sentence| token|
+--------------------+---+--------------------+--------------------+--------------------+
|This is a very us...| 0|[[document, 0, 35...|[[document, 0, 35...|[[token, 0, 3, Th...|
+--------------------+---+--------------------+--------------------+--------------------+
Exception in thread "main" java.lang.IllegalArgumentException:
requirement failed: Wrong or missing inputCols annotators in NORMALIZER_4bde2f08742a.
Received inputCols: token.
Make sure such annotators exist in your pipeline, with the right output
names and that they have following annotator types: token
It works fine if I directly fit and transform token
in normalizer
It seems that during the explode
/groupBy
/collect_list
, some information is lost, but the schema and data looks the same.
Any idea ?