zhengruifeng commented on a change in pull request #30548:
URL: https://github.com/apache/spark/pull/30548#discussion_r534637440



##########
File path: mllib/src/main/scala/org/apache/spark/ml/feature/Word2Vec.scala
##########
@@ -285,27 +285,33 @@ class Word2VecModel private[ml] (
   @Since("2.0.0")
   override def transform(dataset: Dataset[_]): DataFrame = {
     val outputSchema = transformSchema(dataset.schema, logging = true)
-    val vectors = wordVectors.getVectors
-      .mapValues(vv => Vectors.dense(vv.map(_.toDouble)))
-      .map(identity).toMap // mapValues doesn't return a serializable map 
(SI-7005)
-    val bVectors = dataset.sparkSession.sparkContext.broadcast(vectors)
-    val d = $(vectorSize)
-    val emptyVec = Vectors.sparse(d, Array.emptyIntArray, 
Array.emptyDoubleArray)
-    val word2Vec = udf { sentence: Seq[String] =>
+
+    val bcModel = dataset.sparkSession.sparkContext.broadcast(this.wordVectors)

Review comment:
       > And now I guess, this would re-broadcast every time? that could be 
bad. What do you think?
   
   I agree. I perfer not using broadcasting in `transform`, but this may need 
more discussion. we can keep current behavior for now.
   
   GBT models are also broadcasted in this way for performance since 
[SPARK-7127](https://issues.apache.org/jira/browse/SPARK-7127).
   




----------------------------------------------------------------
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to