zhengruifeng commented on a change in pull request #30548:
URL: https://github.com/apache/spark/pull/30548#discussion_r534606911
##########
File path: mllib/src/main/scala/org/apache/spark/mllib/feature/Word2Vec.scala
##########
@@ -538,9 +538,13 @@ class Word2VecModel private[spark] (
@Since("1.1.0")
def transform(word: String): Vector = {
wordIndex.get(word) match {
- case Some(ind) =>
- val vec = wordVectors.slice(ind * vectorSize, ind * vectorSize +
vectorSize)
- Vectors.dense(vec.map(_.toDouble))
+ case Some(index) =>
+ val size = vectorSize
+ val offset = index * size
+ val array = Array.ofDim[Double](size)
+ var i = 0
+ while (i < size) { array(i) = wordVectors(offset + i); i += 1 }
Review comment:
I guess so, I will do a simple test.
----------------------------------------------------------------
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]