Github user MLnick commented on a diff in the pull request: https://github.com/apache/spark/pull/11812#discussion_r56619432 --- Diff: mllib/src/main/scala/org/apache/spark/mllib/feature/Word2Vec.scala --- @@ -463,12 +465,17 @@ class Word2VecModel private[spark] ( // wordVecNorms: Array of length numWords, each value being the Euclidean norm // of the wordVector. - private val wordVecNorms: Array[Double] = { - val wordVecNorms = new Array[Double](numWords) + private val wordVecNorms: Array[Float] = { + val wordVecNorms = new Array[Float](numWords) var i = 0 while (i < numWords) { val vec = wordVectors.slice(i * vectorSize, i * vectorSize + vectorSize) wordVecNorms(i) = blas.snrm2(vectorSize, vec, 1) + // Normalize wordVectors while keeping the norm value in wordVecNorms + // in case the original value of wordVectors is needed + if(wordVecNorms(i) != 0) { + blas.sscal(vectorSize, 1 / wordVecNorms(i), wordVectors, i * vectorSize, 1) --- End diff -- This changes the semantics of `getVectors`, since they will now be returned as normalized vectors. If we keep a normalized version internally in the model, then `getVectors` needs to be updated to return raw vectors.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org