Github user yinxusen commented on a diff in the pull request:
https://github.com/apache/spark/pull/11142#discussion_r53559520
--- Diff: docs/mllib-feature-extraction.md ---
@@ -192,47 +119,12 @@ Here we assume the extracted file is `text8` and in
same directory as you run th
<div data-lang="scala" markdown="1">
Refer to the [`Word2Vec` Scala
docs](api/scala/index.html#org.apache.spark.mllib.feature.Word2Vec) for details
on the API.
-{% highlight scala %}
-import org.apache.spark._
-import org.apache.spark.rdd._
-import org.apache.spark.SparkContext._
-import org.apache.spark.mllib.feature.{Word2Vec, Word2VecModel}
-
-val input = sc.textFile("text8").map(line => line.split(" ").toSeq)
-
-val word2vec = new Word2Vec()
-
-val model = word2vec.fit(input)
-
-val synonyms = model.findSynonyms("china", 40)
-
-for((synonym, cosineSimilarity) <- synonyms) {
- println(s"$synonym $cosineSimilarity")
-}
-
-// Save and load model
-model.save(sc, "myModelPath")
-val sameModel = Word2VecModel.load(sc, "myModelPath")
-{% endhighlight %}
+{% include_example
scala/org/apache/spark/examples/mllib/Word2VecExample.scala %}
</div>
<div data-lang="python" markdown="1">
Refer to the [`Word2Vec` Python
docs](api/python/pyspark.mllib.html#pyspark.mllib.feature.Word2Vec) for more
details on the API.
-{% highlight python %}
-from pyspark import SparkContext
-from pyspark.mllib.feature import Word2Vec
-
-sc = SparkContext(appName='Word2Vec')
-inp = sc.textFile("text8_lines").map(lambda row: row.split(" "))
-
-word2vec = Word2Vec()
-model = word2vec.fit(inp)
-
-synonyms = model.findSynonyms('china', 40)
-
-for word, cosine_distance in synonyms:
- print("{}: {}".format(word, cosine_distance))
-{% endhighlight %}
+{% include_example python/mllib/word_2_vec_example.py %}
--- End diff --
change the filename according to the python file after you changing the
python example name.
---
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]