Theoremadvanced
SGNS as implicit matrix factorization
Also called Levy-Goldberg theorem.
If every dot product w . c is free, the best skip-gram with k negative samples has w . c = PMI(w, c) - log k, so it factorizes a shifted PMI matrix.
Statement
Let be a multiset of word and context pairs , for example the pairs that a skip-gram model reads from a corpus with a window. Write for the number of copies of in , , and . All logarithms are natural. The pointwise mutual information of a pair is
Each word has a vector and each context a vector . Stack them as the rows of and . Skip-gram with negative sampling (SGNS) with noise samples per pair and the noise distribution maximizes the expected objective
where . Collect the terms of each cell :
Theorem (Levy and Goldberg 2014, Section 3.1). Let and be the words and the contexts with and , and suppose that for every and . Let be the matrix of the shifted PMI, .
- Over all real matrices , the function has exactly one maximizer, .
- If , the global maximizers of are exactly the pairs with . That is, at a global maximum, for every pair.
The hypothesis is the precise form of the condition in the paper, that each product "can assume a value independently of the others". It always holds for . Real embeddings have of a few hundred and of many thousands, so they do not meet it, and their dot products only approximate the shifted PMI.
In plain words
Skip-gram with negative sampling learns a vector for each word and each context. Training pushes the score of every real pair up and the score of random pairs down. If the vectors are long enough that each score can be set on its own, the best score of a pair is a known number: how much more often the two appear together than chance predicts, on a log scale, minus the log of the number of random pairs. So the method fills a table of these numbers and writes it as a product of two thin matrices. This links neural word vectors to older methods that build the same table from counts. With short vectors the table cannot be matched exactly, and the method finds a compromise that cares most about frequent pairs.
Proof
Step 1: the objective splits into cells. The expectation over the noise is . It does not depend on the observed context , so its total weight in is . Hence
and renaming as gives .
Step 2: one cell. Fix and and write and , both positive by the hypothesis. Use and . Then
So is strictly concave and has at most one stationary point. The equation reads . Since , it is , with the one solution
A strictly concave function with a stationary point has its unique maximum there.
Step 3: part 1. The sum has a separate variable in each term. It is at most , and by Step 2 equality holds if and only if for every cell.
Step 4: part 2. For any , , with equality if and only if , by part 1. It remains to show that the bound is reached. Let , and take the singular value decomposition with the nonzero singular values. Put and , padded with zero columns. Then , so the bound is the maximum and the maximizers are exactly the factorizations of .
Worked example. Take two words and two contexts with and . Then and every marginal count is 5. The PMI is on the diagonal and off it. With the shift is , so
For the cell , and , so , as in the matrix. The model then gives the true pair the probability of being real. That is the share of real copies among the real and the noise copies of the pair. Here , so is enough, for example and .
Consequences
- SGNS and count methods fit the same matrix. Under the hypothesis, SGNS and a factorization of the shifted PMI matrix have the same optimum. Levy and Goldberg use this to propose the shifted positive PMI, , as a sparse count-based alternative, factored by a truncated SVD as in latent semantic analysis. See also positive pointwise mutual information.
- The smoothed noise distribution. word2vec draws noise from the unigram distribution to the power 3/4, not from (footnote 1 of the paper). The same proof with in place of gives . Since gives more mass to rare contexts than , rare contexts get a lower score. Levy, Goldberg and Dagan 2015 call this context distribution smoothing and apply it to PMI.
- NCE. The same cell analysis for noise-contrastive estimation gives (equation 8 of the paper): NCE fits a shifted log conditional probability, not a PMI.
- Unseen pairs. If while , then and increases as . The supremum is not reached, which matches . The real matrix of a corpus has many such cells, so the exact optimum does not exist there, and the low dimension and the training keep the scores finite.
- Low dimension. With , SGNS maximizes over matrices of rank at most . Near the optimum has the curvature , which grows with the counts, so the fit is a weighted factorization that pays more attention to frequent pairs (Section 3.2 of the paper). GloVe makes a weighted least squares fit of the log counts explicit.
Tightness
Each hypothesis is needed.
- Dimension. In the worked example has rank 2, since . With every has rank at most 1, so no pair reaches , and the global maximum of has some cell with .
- Global maximum, not any stationary point. The point , is stationary: the gradient of with respect to is , which is zero when every , and the same holds for . There every product is 0, not the shifted PMI. The objective is not concave in , so the theorem speaks of its global maxima.
- Positive counts. Without the maximum does not exist, as shown under Consequences.
- The expected objective. The theorem is about the expectation over the noise samples. Stochastic training with a finite number of epochs, a decaying learning rate, subsampling of frequent words and a dynamic window reaches an approximation, and the subsampling and the window change the effective counts .
History
Mikolov, Sutskever, Chen, Corrado and Dean introduced negative sampling in 2013 as a simplification of NCE for the skip-gram model. Goldberg and Levy wrote out its objective as a sum over pairs in an arXiv note in early 2014. Levy and Goldberg then showed at NIPS 2014 that its optimum with free dot products is the shifted PMI matrix. This tied the neural method to the PMI matrices of distributional semantics. Levy, Goldberg and Dagan 2015 carried the tuning choices of word2vec, such as the smoothed context distribution, over to the count methods and found the gaps between the two families small in their experiments.
References
- Levy and Goldberg 2014, Section 2 (the SGNS objective, equations 1 and 2), Section 3.1 (the cell objective, equation 5, and its optimum, equations 6 and 7; the paper has no numbered theorem), equation 8 (the same analysis for NCE), Section 3.2 (weighted factorization when d is small), footnote 1 (the smoothed noise distribution)
- Mikolov, Sutskever, Chen, Corrado and Dean 2013, the negative sampling objective and the unigram noise distribution to the power 3/4
- Goldberg and Levy 2014, the derivation of the negative sampling objective as a sum over word and context pairs
- Levy, Goldberg and Dagan 2015, the smoothed context distribution and the comparison of SGNS with PPMI and SVD
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W0 stub |
|
Tag Y7VQ1F Edit this page History Report an error Markdown