Skip to content

How to explode all predicted classes in Spark NLP into columns #6396

Discussion options

You must be logged in to vote

Answered by @Dirkster99 🙏

Workflow to Unpack Category Array into Seperate Columns

df.select('Id', F.explode(F.arrays_zip("category.result", "category.metadata")).alias("entities")).printSchema()

Output:

root
 |-- Id: string (nullable = true)
 |-- entities: struct (nullable = false)
 |    |-- 0: string (nullable = true)
 |    |-- 1: struct (nullable = true)
 |    |    |-- Class1: string (nullable = true)
 |    |    |-- Class2: string (nullable = true)
 |    |    |-- Class3: string (nullable = true)
 |    |    |-- Class4: string (nullable = true)
 |    |    |-- Class5: string (nullable = true)
 |    |    |-- Class6: string (nullable = true)
 |    |    |-- Class7: string (nullable = true)
 |…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by maziyarpanahi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant