Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/5291#discussion_r27503509
--- Diff:
mllib/src/test/scala/org/apache/spark/mllib/feature/Word2VecSuite.scala ---
@@ -51,4 +54,28 @@ class Word2VecSuite extends FunSuite with
MLlibTestSparkContext {
assert(syms(0)._1 == "taiwan")
assert(syms(1)._1 == "japan")
}
+
+ test("model load / save") {
+
+ val word2VecMap = Map(
+ ("china", Array(0.50f, 0.50f, 0.50f, 0.50f)),
+ ("japan", Array(0.40f, 0.50f, 0.50f, 0.50f)),
+ ("taiwan", Array(0.60f, 0.50f, 0.50f, 0.50f)),
+ ("korea", Array(0.45f, 0.60f, 0.60f, 0.60f))
+ )
+ val model = new Word2VecModel(word2VecMap)
+
+ val tempDir = Utils.createTempDir()
+ val path = tempDir.toURI.toString
+
+ try {
+ model.save(sc, path)
+ val sameModel = Word2VecModel.load(sc, path)
+ assert(sameModel.getVectors.keys === model.getVectors.keys)
--- End diff --
The ordering of keys are not guaranteed. We could test map equals directly.
~~~scala
assert(sameModel.getVectors.mapValues(_.toSeq) ===
model.getVectors.mapValues(_.toSeq))
~~~
---
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]