Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentAssembler on array<string> #13816

Closed
1 task done
HeyBossy opened this issue May 23, 2023 · 8 comments · Fixed by #13798
Closed
1 task done

DocumentAssembler on array<string> #13816

HeyBossy opened this issue May 23, 2023 · 8 comments · Fixed by #13798

Comments

@HeyBossy
Copy link

Is there an existing issue for this?

  • I have searched the existing issues and did not find a match.

Who can help?

No response

What are you working on?

I don't know why but my question was deleted. Therefore, I will repeat again.
I am working with a dataframe that I need to lemmatize. There, the input is an array of strings. I am trying to use DocumentAssembler for array of strings. The documentation says: "The DocumentAssembler can read either a String column or an Array[String])". But it doesn't work like that for me. Can you explain what I'm doing wrong? Or is the documentation out of date?

Current Behavior

I am getting an error

AnalysisException: [CANNOT_UP_CAST_DATATYPE] Cannot up cast input from "ARRAY<STRING>" to "STRING".
The type path of the target object is:
- root class: "java.lang.String"
You can either add an explicit cast to the input data or choose a higher precision type of the field in the target object

Expected Behavior

Steps To Reproduce

When I do a simple example:

data = spark.createDataFrame([[["Spark NLP is an open-source text processing library."]]]).toDF("text")
documentAssembler = DocumentAssembler().setInputCol("text").setOutputCol("document")
result = documentAssembler.transform(data)

result.select("document").show(truncate=False

Spark NLP version and Apache Spark

sparknlp.version() == '4.4.0'
spark.version == '3.4.0'

Type of Spark Application

No response

Java Version

No response

Java Home Directory

No response

Setup and installation

No response

Operating System and Version

No response

Link to your project (if available)

No response

Additional Information

No response

@maziyarpanahi
Copy link
Member

@HeyBossy your question was not deleted, it was answered with an example and a Colab link: #13815

Please have a look at our step-by-step tutorials to get started with Spark NLP. (the input for DocumentAssembler must be STRING

https://github.com/JohnSnowLabs/spark-nlp-workshop/tree/master/open-source-nlp

@maziyarpanahi
Copy link
Member

leaving it open to avoid another duplicate question. @HeyBossy please close it once you read the answer

@HeyBossy
Copy link
Author

I didn't do extra square brackets. I want to submit type array string.

root
 |-- text: array (nullable = true)
 |    |-- element: string (containsNull = true)

The DocumentAssembler can read either a String column or an Array[String])
Can you explain to me what this means, I don't understand.

@HeyBossy
Copy link
Author

@maziyarpanahi
Copy link
Member

I see the problem now, I didn't see the docs saying that. The documentation is wrong! Actually, DocumentAssembler only accepts String - I will ask for the docs to be fixed (everywhere for this)

@HeyBossy As a workaround, you need to explode your array of text and then that can be used as an input to

@maziyarpanahi
Copy link
Member

@DevinTDHa Could you please make sure this is fixed in all the docs (pydoc, scaladoc, website, etc.) - many thanks

@HeyBossy
Copy link
Author

Okay I got it, thanks for the replies!

@maziyarpanahi
Copy link
Member

Thanks @HeyBossy

re-opening this, it gets closed once we fixed this issue in the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants