-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-22735][ML][DOC] Added VectorSizeHint docs and examples. #20285
Conversation
Test build #86223 has finished for PR 20285 at commit
|
Test build #86221 has finished for PR 20285 at commit
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor things, but looks pretty good, could you post a screenshot of the doc after building? Are you planning on adding a Java example?
docs/ml-features.md
Outdated
@@ -1283,6 +1283,48 @@ for more details on the API. | |||
</div> | |||
</div> | |||
|
|||
## VectorSizeHint | |||
|
|||
It can sometimes be useful to explicitly specify the size of the vectors an a column of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo 'an a column' -> 'in a column'
docs/ml-features.md
Outdated
meatadata. | ||
|
||
`VectorSizeHint` can also take an optional `handleInvalid` parameter which controls its | ||
behaviour when the vector column contains nulls for vectors of the wrong size. By default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: 'nulls for vectors..' -> 'nulls or vectors'
if __name__ == "__main__": | ||
spark = SparkSession\ | ||
.builder\ | ||
.appName("VectorAssemblerExample")\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be "VectorSizeHintExample" - same with other apis
|
||
sizeHint = VectorSizeHint( | ||
inputCol="userFeatures", | ||
handleInvalid="sip", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo "sip" -> "skip"
Test build #86287 has finished for PR 20285 at commit
|
Thanks for the review @BryanCutler, I've added a java example & uploaded 2 screenshots. |
Test build #86302 has finished for PR 20285 at commit
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, LGTM!
import static org.apache.spark.sql.types.DataTypes.*; | ||
|
||
// $example on$ | ||
// $example off$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the above two lines?
inputCols=["hour", "mobile", "userFeatures"], | ||
outputCol="features") | ||
|
||
# This dataframe can be used by used by downstream transformers as before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is some typos here.
.setInputCols(Array("hour", "mobile", "userFeatures")) | ||
.setOutputCol("features") | ||
|
||
// This dataframe can be used by used by downstream transformers as before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
docs/ml-features.md
Outdated
@@ -1283,6 +1283,56 @@ for more details on the API. | |||
</div> | |||
</div> | |||
|
|||
## VectorSizeHint | |||
|
|||
It can sometimes be useful to explicitly specify the size of the vectors a column of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a column of Vector
-> for a column of Vector
?
docs/ml-features.md
Outdated
`VectorType`. For example, `VectorAssembler` uses size information from its input columns to | ||
produce size information and metadata for its output column. While in some cases this information | ||
can be obtained by inspecting the contents of the column, in a streaming dataframe the contents are | ||
not available until the stream is started. `VectorSizeHint` allows a user to explicitly specify the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a user -> an user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if the spark style guide covers this, but I believe "a user" is generally the prefered form, https://english.stackexchange.com/a/105117.
vector size for a column so that `VectorAssembler`, or other transformers that might | ||
need to know vector size, can use that column as an input. | ||
|
||
To use `VectorSizeHint` a user must set the `inputCol` and `size` parameters. Applying this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a user -> an user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a user
is correct because users
's pronunciation starts with y
Test build #86366 has finished for PR 20285 at commit
|
I'd like to prioritize getting this merged to ensure our documentation is complete for the 2.3 release. @viirya and @WeichenXu123 would you mind having another look at it? |
createStructField("userFeatures", new VectorUDT(), false), | ||
createStructField("clicked", DoubleType, false) | ||
}); | ||
Row row = RowFactory.create(0, 18, 1.0, Vectors.dense(0.0, 10.0, 0.5), 1.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @MrBago . It seems that we need to add one more row here.
RowFactory.create(0, 18, 1.0, Vectors.dense(0.0, 10.0), 0.0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except a minor comment. 👍
docs/ml-features.md
Outdated
`handleInvalid` is set to "error", indicating an exception should be thrown. This parameter can | ||
also be set to "skip", indicating that rows containing invalid values should be filtered out from | ||
the resulting dataframe, or `optimistic` indicating that all rows should be kept. When | ||
`handleInvalid` is set to `optimistic` the user takes responsibility for ensuring that the column |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optimistic
--> "optimistic"
the backquote only used on code vars.
createStructField("clicked", DoubleType, false) | ||
}); | ||
Row row0 = RowFactory.create(0, 18, 1.0, Vectors.dense(0.0, 10.0, 0.5), 1.0); | ||
Row row1 = RowFactory.create(0, 18, 1.0, Vectors.dense(0.0, 10.0, 0.5), 1.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the same data set with the other code?
I mean the second row is different from what I suggested and the other examples'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, yes should be fixed now.
Test build #86541 has finished for PR 20285 at commit
|
Test build #86543 has finished for PR 20285 at commit
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
docs/ml-features.md
Outdated
`handleInvalid` is set to "error", indicating an exception should be thrown. This parameter can | ||
also be set to "skip", indicating that rows containing invalid values should be filtered out from | ||
the resulting dataframe, or "optimistic" indicating that all rows should be kept. When | ||
`handleInvalid` is set to "optimistic" the user takes responsibility for ensuring that the column |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not clear to me what is the expected behaivor of optimistic
. How is it different from error
? Does it output null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated it, let me know if you think we can still make it more clear.
<div class="codetabs"> | ||
<div data-lang="scala" markdown="1"> | ||
|
||
Refer to the [VectorSizeHint Scala docs](api/scala/index.html#org.apache.spark.ml.feature.VectorSizeHint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: Do we need to mention Scala
explicitly here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Merged into master and branch-2.3. Thanks! |
## What changes were proposed in this pull request? Added documentation for new transformer. Author: Bago Amirbekian <[email protected]> Closes #20285 from MrBago/sizeHintDocs. (cherry picked from commit 05839d1) Signed-off-by: Xiangrui Meng <[email protected]>
Test build #86548 has finished for PR 20285 at commit
|
Hi, @mengxr . Thanks! |
What changes were proposed in this pull request?
Added documentation for new transformer.