Github user MechCoder commented on a diff in the pull request:
https://github.com/apache/spark/pull/7263#discussion_r34118525
--- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/Word2Vec.scala
---
@@ -146,6 +151,55 @@ class Word2VecModel private[ml] (
wordVectors: feature.Word2VecModel)
extends Model[Word2VecModel] with Word2VecBase {
+
+ /**
+ * Return a map of every word to its Vector representation.
+ */
+ val getVectors: Map[String, Array[Float]] = wordVectors.getVectors
+
+ /**
+ * Java friendly version of getVectors called by the python wrappers.
+ */
+ private[spark] val javaGetVectors: JList[Object] = {
+ val (words, vectors) = getVectors.toSeq.unzip
+
+ // There are problems with serialization of Arrays which makes this
conversion
+ // necessary.
+ val vectorsList = vectors.toList.map(vec =>
Vectors.dense(vec.map(_.toDouble)))
+ List(words.toList,
vectorsList).map(_.asJava.asInstanceOf[Object]).asJava
+ }
+
+ /**
+ * Find "num" no. words closest to similarity to the given word.
+ * Returns a coupled array with the second element giving the similarity
measure.
+ */
+ def findSynonyms(word: String, num: Int): Array[(String, Double)] = {
--- End diff --
Hmm. I had a similar thought in mind. If I do that I could remove the
"java-friendly" code below.
@mengxr thoughts?
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]