KGE.constraint

Functions

Lp_regularization(X, p, axis)

Standard Lp-regularization

clip_constraint(X, p, value, axis)

Clip embeddings

normalized_embeddings(X, p, value, axis)

Normalized embeddings

soft_constraint(X, p, value, axis)

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 regularized

  • p (int) – p-norm

  • axis (int or tuple) – along what axis

Returns

constraint term

Return type

tf.Tensor

KGE.constraint.clip_constraint(X, p, value, axis)[source]

Clip embeddings

If X’s p-norm exceeds value, clip the value that let p-norm of X equals value.

Parameters
  • X (tf.Tensor) – Tensor to be constraint

  • p (int) – p-norm

  • value (float) – restrict value

  • axis (int or tuple) – 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 X into p-norm equals value.

Parameters
  • X (tf.Tensor) – Tensor to be normalized

  • p (int) – p-norm

  • value (float) – restrict value

  • axis (int or tuple) – 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 constraint

  • p (int) – p-norm

  • value (float) – restrict value

  • axis (int or tuple) – along what axis

Returns

regularization term

Return type

tf.Tensor