KGE.constraint
Functions
|
Standard Lp-regularization |
|
Clip embeddings |
|
Normalized embeddings |
|
Soft constraint |
- KGE.constraint.Lp_regularization(X, p, axis)[source]
Standard Lp-regularization
The standard Lp-regularization:
- ..math ::
- regularization ~ term =
sum left| X right|_p^p
- Parameters
X (
tf.Tensor) – Tensor to be regularizedp (
int) – p-normaxis (
intortuple) – along what axis
- Returns
constraint term
- Return type
tf.Tensor
- KGE.constraint.clip_constraint(X, p, value, axis)[source]
Clip embeddings
If
X’sp-norm exceedsvalue, clip the value that letp-norm ofXequalsvalue.- Parameters
X (
tf.Tensor) – Tensor to be constraintp (
int) – p-normvalue (
float) – restrict valueaxis (
intortuple) – along what axis
- Returns
constraint tensor with same shape as
X- Return type
tf.Tensor
- KGE.constraint.normalized_embeddings(X, p, value, axis)[source]
Normalized embeddings
Normalized
Xintop-norm equalsvalue.- Parameters
X (
tf.Tensor) – Tensor to be normalizedp (
int) – p-normvalue (
float) – restrict valueaxis (
intortuple) – along what axis
- Returns
normalized tensor with same shape as
X- Return type
tf.Tensor
- KGE.constraint.soft_constraint(X, p, value, axis)[source]
Soft constraint
Soft constraint that described in TransH:
\[regularization ~ term = \sum \left[ \left\| \textbf{X} \right\|_p^2 - value \right]_+\]where \([x]_+ = max(0,x)\)
- Parameters
X (
tf.Tensor) – Tensor to be constraintp (
int) – p-normvalue (
float) – restrict valueaxis (
intortuple) – along what axis
- Returns
regularization term
- Return type
tf.Tensor