View source: R/utils-embedding-matrices.R
| weight_ppmi | R Documentation |
Computes the positive pointwise mutual information (PPMI) weighting of a term co-occurrence matrix (TCM). PPMI is a standard transformation applied prior to building word embeddings via matrix factorization (e.g. SVD): it down-weights chance co-occurrences and clips negative associations to zero, yielding a non-negative matrix amenable to factorization.
weight_ppmi(tcm, smooth = 0)
tcm |
A term co-occurrence matrix; either a dense |
smooth |
A non-negative numeric scalar added to every cell of |
The estimator uses marginal probabilities (row and column sums) rather than a diagonal-count proxy, following the standard formulation of Levy & Goldberg (2014). Smoothing, if requested, is applied to the raw counts (including zero cells) before estimating probabilities.
A sparse dgCMatrix of the same dimensions as tcm containing
PPMI weights, with row and column names preserved.
Dustin Stoltz
Levy, O., & Goldberg, Y. (2014). Neural word embedding as implicit matrix factorization. Advances in Neural Information Processing Systems (NeurIPS).
tcm <- matrix(c(2, 1, 0, 1, 3, 1, 0, 1, 2), nrow = 3,
dimnames = list(c("a", "b", "c"), c("a", "b", "c")))
weight_ppmi(tcm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.