You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wor2Vec computes distributed vector representation of words. The main advantage of the distributed representations is that similar words are close in the vector space, which makes generalization to novel patterns easier and model estimation more robust. Distributed vector representation is showed to be useful in many natural language processing applications such as named entity recognition, disambiguation, parsing, tagging and machine translation.
12
+
Wor2Vec computes distributed vector representation of words. The main advantage of the distributed
13
+
representations is that similar words are close in the vector space, which makes generalization to
14
+
novel patterns easier and model estimation more robust. Distributed vector representation is
15
+
showed to be useful in many natural language processing applications such as named entity
16
+
recognition, disambiguation, parsing, tagging and machine translation.
13
17
14
18
### Model
15
-
In our implementation of Word2Vec, we used skip-gram model. The training objective of skip-gram is to learn word vector representations that are good at predicting its context in the same sentence. Mathematically, given a sequence of training words `$w_1, w_2, \dots, w_T$`, the objective of the skip-gram model is to maximize the average log-likelihood
19
+
20
+
In our implementation of Word2Vec, we used skip-gram model. The training objective of skip-gram is
21
+
to learn word vector representations that are good at predicting its context in the same sentence.
22
+
Mathematically, given a sequence of training words `$w_1, w_2, \dots, w_T$`, the objective of the
23
+
skip-gram model is to maximize the average log-likelihood
In the skip-gram model, every word $w$ is associated with two vectors $u_w$ and $v_w$ which are vector representations of $w$ as word and context respectively. The probability of correctly predicting word $w_i$ given word $w_j$ is determined by the softmax model, which is
29
+
In the skip-gram model, every word $w$ is associated with two vectors $u_w$ and $v_w$ which are
30
+
vector representations of $w$ as word and context respectively. The probability of correctly
31
+
predicting word $w_i$ given word $w_j$ is determined by the softmax model, which is
The skip-gram model with softmax is expensive because the cost of computing $\log p(w_i | w_j)$
28
-
is proportional to $V$, which can be easily in order of millions. To speed up Word2Vec training, we used hierarchical softmax, which reduced the complexity of computing of $\log p(w_i | w_j)$ to
38
+
is proportional to $V$, which can be easily in order of millions. To speed up training of Word2Vec,
39
+
we used hierarchical softmax, which reduced the complexity of computing of $\log p(w_i | w_j)$ to
29
40
$O(\log(V))$
30
41
31
42
### Example
32
43
33
-
The example below demonstrates how to load a text file, parse it as an RDD of `Seq[String]` and then construct a `Word2Vec` instance with specified parameters. Then we fit a Word2Vec model with the input data. Finally, we display the top 40 similar words to the specified word.
44
+
The example below demonstrates how to load a text file, parse it as an RDD of `Seq[String]`,
45
+
construct a `Word2Vec` instance and then fit a `Word2VecModel` with the input data. Finally,
46
+
we display the top 40 synonyms of the specified word. To run the example, first download
47
+
the [text8](http://mattmahoney.net/dc/text8.zip) data and extract it to your preferred directory.
48
+
Here we assume the extracted file is `text8` and in same directory as you run the spark shell.
34
49
35
50
<divclass="codetabs">
36
51
<divdata-lang="scala">
@@ -40,27 +55,19 @@ import org.apache.spark.rdd._
40
55
import org.apache.spark.SparkContext._
41
56
import org.apache.spark.mllib.feature.Word2Vec
42
57
43
-
val input = sc.textFile().map(line => line.split(" ").toSeq)
44
-
val size = 100
45
-
val startingAlpha = 0.025
46
-
val numPartitions = 1
47
-
val numIterations = 1
58
+
val input = sc.textFile("text8").map(line => line.split(" ").toSeq)
0 commit comments