zhengruifeng commented on a change in pull request #26547: [SPARK-29914][ML] ML
models attach metadata in `transform`/`transformSchema`
URL: https://github.com/apache/spark/pull/26547#discussion_r354081572
##########
File path:
mllib/src/main/scala/org/apache/spark/ml/feature/CountVectorizer.scala
##########
@@ -326,14 +326,19 @@ class CountVectorizerModel(
Vectors.sparse(dictBr.value.size, effectiveCounts)
}
- val attrs = vocabulary.map(_ => new
NumericAttribute).asInstanceOf[Array[Attribute]]
- val metadata = new AttributeGroup($(outputCol), attrs).toMetadata()
- dataset.withColumn($(outputCol), vectorizer(col($(inputCol))), metadata)
+ dataset.withColumn($(outputCol), vectorizer(col($(inputCol))),
+ outputSchema($(outputCol)).metadata)
}
@Since("1.5.0")
override def transformSchema(schema: StructType): StructType = {
- validateAndTransformSchema(schema)
+ var outputSchema = validateAndTransformSchema(schema)
+ if ($(outputCol).nonEmpty) {
+ val attrs: Array[Attribute] = vocabulary.map(_ => new NumericAttribute)
+ val field = new AttributeGroup($(outputCol), attrs).toStructField()
+ outputSchema = SchemaUtils.updateField(outputSchema, field)
Review comment:
Sounds reasonable, I think we may change this place by only attach a `size`.
I will send a follow up.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]