Github user yanboliang commented on a diff in the pull request: https://github.com/apache/spark/pull/17451#discussion_r123925086 --- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/Word2Vec.scala --- @@ -274,6 +274,31 @@ class Word2VecModel private[ml] ( wordVectors.findSynonyms(word, num) } + /** + * Find "num" number of words whose vector representation is most similar to the supplied vector. + * If the supplied vector is the vector representation of a word in the model's vocabulary, + * that word will be in the results. + * @return a tuple of the words list and the cosine similarities list between the synonyms given + * word vector. + */ + @Since("2.2.0") + def findSynonymsTuple(vec: Vector, num: Int): (Array[String], Array[Double]) = { + val result = findSynonymsArray(vec, num) + (result.map(e => e._1), result.map(e => e._2)) + } + + /** + * Find "num" number of words closest in similarity to the given word, not + * including the word itself. + * @return a tuple of the words list and the cosine similarities list between the synonyms given + * word vector. + */ + @Since("2.2.0") + def findSynonymsTuple(word: String, num: Int): (Array[String], Array[Double]) = { --- End diff -- Ditto, should be private.
--- 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