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

Use DocumentAssembler on array<string> #13815

Closed
1 task done
HeyBossy opened this issue May 22, 2023 · 1 comment
Closed
1 task done

Use DocumentAssembler on array<string> #13815

HeyBossy opened this issue May 22, 2023 · 1 comment
Assignees
Labels

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 am trying to use DocumentAssembler for array of strings. The documentation says: "The DocumentAssembler can read either a String column or an Array[String])"

Current Behavior

But 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

For example, I want to submit a text column (type array string) to a document.

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

Spark NLP version sparknlp.version(): 4.4.0
Apache NLP version 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

as the error indicates you have an array instead of a string. (you have one extra [] in your DataFrame)

# [[STRING HERE]]
data = spark.createDataFrame([["Spark NLP is an open-source text processing library."]]).toDF("text")

data.show()

example: https://colab.research.google.com/drive/1gh9GSoIJZCpWGocS_Ea6kNrjbZnA_3Mx?usp=sharing

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

No branches or pull requests

2 participants