如何运行 MLlib的word2vec在CBOW模式下?
How to run MLlib's word2vec in CBOW mode?
我的理解是word2vec可以运行两种模式:
- 连续词袋(CBOW)(词序无关紧要)
- continuous skip-gram(词序很重要)
我想 运行 来自 Spark 的 MLlib 的 CBOW 实现,但是从文档和他们的示例中我不清楚如何去做。这是他们页面上列出的示例。
发件人:https://spark.apache.org/docs/2.1.0/mllib-feature-extraction.html#example
import org.apache.spark.mllib.feature.{Word2Vec, Word2VecModel}
val input = sc.textFile("data/mllib/sample_lda_data.txt").map(line => line.split(" ").toSeq)
val word2vec = new Word2Vec()
val model = word2vec.fit(input)
val synonyms = model.findSynonyms("1", 5)
for((synonym, cosineSimilarity) <- synonyms) {
println(s"$synonym $cosineSimilarity")
}
我的问题:
- 这个例子使用了两种模式中的哪一种?
- 你知道我如何运行模型在CBOW模式下吗?
提前致谢!
似乎 MLlib 目前只实现了 skip-gram。
这是 skip-gram 模型的公开 ticket/pull 请求:https://issues.apache.org/jira/browse/SPARK-20372
我的理解是word2vec可以运行两种模式:
- 连续词袋(CBOW)(词序无关紧要)
- continuous skip-gram(词序很重要)
我想 运行 来自 Spark 的 MLlib 的 CBOW 实现,但是从文档和他们的示例中我不清楚如何去做。这是他们页面上列出的示例。
发件人:https://spark.apache.org/docs/2.1.0/mllib-feature-extraction.html#example
import org.apache.spark.mllib.feature.{Word2Vec, Word2VecModel}
val input = sc.textFile("data/mllib/sample_lda_data.txt").map(line => line.split(" ").toSeq)
val word2vec = new Word2Vec()
val model = word2vec.fit(input)
val synonyms = model.findSynonyms("1", 5)
for((synonym, cosineSimilarity) <- synonyms) {
println(s"$synonym $cosineSimilarity")
}
我的问题:
- 这个例子使用了两种模式中的哪一种?
- 你知道我如何运行模型在CBOW模式下吗?
提前致谢!
似乎 MLlib 目前只实现了 skip-gram。
这是 skip-gram 模型的公开 ticket/pull 请求:https://issues.apache.org/jira/browse/SPARK-20372