zhengruifeng commented on code in PR #49614:
URL: https://github.com/apache/spark/pull/49614#discussion_r1926383494
##########
python/pyspark/ml/tests/test_feature.py:
##########
@@ -357,6 +359,48 @@ def test_robust_scaler(self):
self.assertEqual(str(model), str(model2))
self.assertEqual(model2.getOutputCol(), "scaled")
+ def test_word2vec(self):
+ sent = ("a b " * 100 + "a c " * 10).split(" ")
+ df = self.spark.createDataFrame([(sent,), (sent,)],
["sentence"]).coalesce(1)
+
+ w2v = Word2Vec(vectorSize=3, seed=42, inputCol="sentence",
outputCol="model")
+ w2v.setMaxIter(1)
+ self.assertEqual(w2v.getInputCol(), "sentence")
+ self.assertEqual(w2v.getOutputCol(), "model")
+ self.assertEqual(w2v.getVectorSize(), 3)
+ self.assertEqual(w2v.getSeed(), 42)
+ self.assertEqual(w2v.getMaxIter(), 1)
+
+ model = w2v.fit(df)
+ self.assertEqual(model.getVectors().columns, ["word", "vector"])
+ self.assertEqual(model.getVectors().count(), 3)
+
+ synonyms = model.findSynonyms("a", 2)
+ self.assertEqual(synonyms.columns, ["word", "similarity"])
+ self.assertEqual(synonyms.count(), 2)
+
+ # TODO(SPARK-50958): Support Word2VecModel.findSynonymsArray
Review Comment:
`Word2VecModel.findSynonymsArray` returns a complex type, cannot be
automatically handled by literal, will try to fix it later
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]