Loss

class ampligraph.latent_features.Loss(eta, hyperparam_dict, verbose=False)

Abstract class for loss function.

Methods

__init__(eta, hyperparam_dict[, verbose]) Initialize Loss.
get_state(param_name) Get the state value.
_init_hyperparams(hyperparam_dict) Initializes the hyperparameters needed by the algorithm.
_inputs_check(scores_pos, scores_neg) Creates any dependencies that need to be checked before performing loss computations
apply(scores_pos, scores_neg) Interface to external world.
_apply(scores_pos, scores_neg) Apply the loss function.
__init__(eta, hyperparam_dict, verbose=False)

Initialize Loss.

Parameters:
  • eta (int) – number of negatives
  • hyperparam_dict (dict) – dictionary of hyperparams. (Keys are described in the hyperparameters section)
get_state(param_name)

Get the state value.

Parameters:param_name (string) – Name of the state for which one wants to query the value.
Returns:The value of the corresponding state.
Return type:param_value
_init_hyperparams(hyperparam_dict)

Initializes the hyperparameters needed by the algorithm.

Parameters:hyperparam_dict (dictionary) – Consists of key value pairs. The Loss will check the keys to get the corresponding params.
_inputs_check(scores_pos, scores_neg)

Creates any dependencies that need to be checked before performing loss computations

Parameters:
  • scores_pos (tf.Tensor) – A tensor of scores assigned to positive statements.
  • scores_neg (tf.Tensor) – A tensor of scores assigned to negative statements.
apply(scores_pos, scores_neg)

Interface to external world. This function does the input checks, preprocesses input and finally applies loss function.

Parameters:
  • scores_pos (tf.Tensor) – A tensor of scores assigned to positive statements.
  • scores_neg (tf.Tensor) – A tensor of scores assigned to negative statements.
Returns:

loss – The loss value that must be minimized.

Return type:

tf.Tensor

_apply(scores_pos, scores_neg)

Apply the loss function. Every inherited class must implement this function. (All the TF code must go in this function.)

Parameters:
  • scores_pos (tf.Tensor) – A tensor of scores assigned to positive statements.
  • scores_neg (tf.Tensor) – A tensor of scores assigned to negative statements.
Returns:

loss – The loss value that must be minimized.

Return type:

tf.Tensor