mangoes.weighting module¶
Weighting transformations to apply to the co-occurrence count matrix.
This module provides transformations that can be used in the transformations parameter of
the mangoes.create_representation()
function to create an Embeddings from a CountBasedRepresentation.
Examples¶
>>> import mangoes.base
>>> ppmi = mangoes.weighting.PPMI(alpha=1)
>>> embeddings = mangoes.base.create_representation(cc, transformations=ppmi)
See Also¶
mangoes.create_representation()
mangoes.Transformation
-
class
mangoes.weighting.
JointProbabilities
¶ Bases:
mangoes.base.Transformation
Defines a transformation that replaces counts with joint probabilities computed from these counts
- Attributes
- params
Methods
__call__
(matrix)From matrix = [#(wi,cj)], compute the matrix [P(wi,cj)].
-
class
mangoes.weighting.
ConditionalProbabilities
¶ Bases:
mangoes.base.Transformation
Defines a transformation that replaces counts with joint probabilities computed from these counts
- Attributes
- params
Methods
__call__
(matrix)From matrix = [#(wi,cj)], compute the matrix [P(cj|wi)].
-
class
mangoes.weighting.
ProbabilitiesRatio
(alpha=1)¶ Bases:
mangoes.base.Transformation
Defines a transformation that replaces counts with joint probabilities computed from these counts
- Attributes
- alpha: int, optional
positive number (default=1); “smoothing” parameter for the computation of the context probability distributions: P(c_j) = (#c_j)**alpha / sum((#c_k)**alpha)
Methods
__call__
(matrix)From matrix = [#(wi,cj)], compute the matrix [P(cj|wi) / P(cj)].
-
property
alpha
¶
-
class
mangoes.weighting.
PMI
(alpha=1)¶ Bases:
mangoes.base.Transformation
Defines a PMI (Pointwise Mutual Information) transformation
- Attributes
- alpha: int, optional
positive number (default=1); “smoothing” parameter for the computation of the context probability distributions: P(c_j) = (#c_j)**alpha / sum((#c_k)**alpha)
Methods
__call__
(matrix)From matrix = [#(wi,cj)], compute the ‘pmi’ matrix [log(P(cj|wi)/P(cj)) or 0 if not defined].
-
property
alpha
¶
-
class
mangoes.weighting.
PPMI
(alpha=1)¶ Bases:
mangoes.weighting.PMI
Defines a PPMI (Positive PMI) transformation.
- Returns
- matrix-like object
- Attributes
- alpha: int, optional
positive number (default=1); “smoothing” parameter for the computation of the context probability distributions: P(c_j) = (#c_j)**alpha / sum((#c_k)**alpha)
Methods
__call__
(matrix)From matrix = [#(wi,cj)], compute the ‘ppmi’ matrix [max(log(P(cj|wi)/P(cj)) or 0 if not defined, 0)].
-
class
mangoes.weighting.
ShiftedPPMI
(alpha=1, shift=1)¶ Bases:
mangoes.weighting.PMI
Defines a Shifted PPMI (Positive PMI) transformation
From matrix = [#(wi,cj)], compute the matrix [max(log(P(cj|wi)/P(cj))-log(shift) or 0 if not defined, 0)]
- Returns
- matrix-like object
- Attributes
- alpha: int, optional
positive number (default=1); “smoothing” parameter for the computation of the context probability distributions: P(c_j) = (#c_j)**alpha / sum((#c_k)**alpha)
- shift: int, optional
number superior or equal to 1 (default=1); The result matrix will be shifted of log(shift)
Methods
__call__
(matrix)From matrix = [#(wi,cj)], compute the matrix [max(log(P(cj|wi)/P(cj))-log(shift) or 0 if not defined, 0)].
-
property
shift
¶
-
class
mangoes.weighting.
TFIDF
¶ Bases:
mangoes.base.Transformation
Defines a TF-IDF (term frequency-inverse document frequency) transformation
- Attributes
- params
Methods
__call__
(matrix)From matrix = [#(wi,cj)], computes a tfidf matrix [tf(wi,cj) * idf(wi)]