Losses¶
RelevanceLossBase¶
-
class
ml4ir.base.model.losses.loss_base.RelevanceLossBase¶ Bases:
objectAbstract class that defines the loss and final activation function used to train a RelevanceModel
-
get_loss_fn(**kwargs)¶ Returns the loss function _loss_fn()
Parameters: kwargs (dict) – Additional key value arguments can be passed as needed. For example, metadata features can be passed to compute custom losses Returns: Loss function that computes the loss from predicted scores and true labels Return type: function
-
get_final_activation_op()¶ Returns the final activation layer
Returns: Final activation function that is applied on the scores before computing losses Return type: function
-
SigmoidCrossEntropy¶
-
class
ml4ir.applications.ranking.model.losses.pointwise_losses.SigmoidCrossEntropy(loss_key, scoring_type)¶ Bases:
ml4ir.applications.ranking.model.losses.loss_base.PointwiseLossBaseInstantiate a PointwiseLossBase object
Parameters: - loss_key (str) – Name of the loss function used
- scoring_type (str) – Type of scoring function - pointwise, pairwise, groupwise
-
get_loss_fn(**kwargs)¶ Define a sigmoid cross entropy loss Additionally can pass in record positions to handle positional bias
Returns: Function to compute sigmoid cross entropy loss Return type: function Notes
Uses mask field to exclude padded records from contributing to the loss
-
get_final_activation_op(output_name)¶ Define a sigmoid activation function
Parameters: output_name (str) – Name of the output score node in the tensorflow model Returns: Function to apply sigmoid activation to the output score Return type: function
RankOneListNet¶
-
class
ml4ir.applications.ranking.model.losses.listwise_losses.RankOneListNet(loss_key, scoring_type)¶ Bases:
ml4ir.applications.ranking.model.losses.loss_base.ListwiseLossBaseInstantiate a ListwiseLossBase object
Parameters: - loss_key (str) – Name of the loss function used
- scoring_type (str) – Type of scoring function - pointwise, pairwise, groupwise
-
get_loss_fn(**kwargs)¶ Define a masked rank 1 ListNet loss Additionally can pass in record positions to handle positional bias
Returns: Function to compute top 1 listnet loss Return type: function Notes
Uses mask field to exclude padded records from contributing to the loss
-
get_final_activation_op(output_name)¶ Define a masked softmax activation function
Parameters: output_name (str) – Name of the output to apply softmax activation on Returns: Function to compute masked softmax Return type: function Notes
Uses mask field to exclude padded records from contributing to the softmax activation
CategoricalCrossEntropy¶
-
class
ml4ir.applications.classification.model.losses.categorical_cross_entropy.CategoricalCrossEntropy¶ Bases:
ml4ir.base.model.losses.loss_base.RelevanceLossBase-
get_loss_fn(**kwargs)¶ Define a categorical cross entropy loss
Returns: Categorical cross entropy loss function Return type: function
-
get_final_activation_op(output_name)¶ Define softmax activation function
Parameters: output_name (str) – Name of the output to use for final activation layer Returns: Softmax activation function Return type: function
-