Scorer¶
ScorerBase¶
-
class
ml4ir.base.model.scoring.scoring_model.ScorerBase(model_config: dict, feature_config: ml4ir.base.features.feature_config.FeatureConfig, interaction_model: ml4ir.base.model.scoring.interaction_model.InteractionModel, loss: ml4ir.base.model.losses.loss_base.RelevanceLossBase, file_io: ml4ir.base.io.file_io.FileIO, output_name: str = 'score', logger: Optional[logging.Logger] = None)¶ Bases:
objectBase Scorer class that defines the neural network layers that convert the input features into scores
Defines the feature transformation layer(InteractionModel), dense neural network layers combined with activation layers and the loss function
Notes
This is an abstract class. In order to use a Scorer, one must define and override the architecture_op and the final_activation_op functions
Constructor method for creating a ScorerBase object
Parameters: - model_config (dict) – Dictionary defining the model layer configuration
- feature_config (FeatureConfig object) – FeatureConfig object defining the features and their configurations
- interaction_model (InteractionModel object) – InteractionModel that defines the feature transformation layers on the input model features
- loss (RelevanceLossBase object) – Relevance loss object that defines the final activation layer and the loss function for the model
- file_io (FileIO object) – FileIO object that handles read and write
- output_name (str, optional) – Name of the output that captures the score computed by the model
- logger (Logger, optional) – Logging handler
-
classmethod
from_model_config_file(model_config_file: str, interaction_model: ml4ir.base.model.scoring.interaction_model.InteractionModel, loss: ml4ir.base.model.losses.loss_base.RelevanceLossBase, file_io: ml4ir.base.io.file_io.FileIO, output_name: str = 'score', feature_config: Optional[ml4ir.base.features.feature_config.FeatureConfig] = None, logger: Optional[logging.Logger] = None)¶ Get a Scorer object from a YAML model config file
Parameters: - model_config_file (str) – Path to YAML file defining the model layer configuration
- feature_config (FeatureConfig object) – FeatureConfig object defining the features and their configurations
- interaction_model (InteractionModel object) – InteractionModel that defines the feature transformation layers on the input model features
- loss (RelevanceLossBase object) – Relevance loss object that defines the final activation layer and the loss function for the model
- file_io (FileIO object) – FileIO object that handles read and write
- output_name (str, optional) – Name of the output that captures the score computed by the model
- logger (Logger, optional) – Logging handler
Returns: ScorerBase object that computes the scores from the input features of the model
Return type: ScorerBase object
-
architecture_op(train_features, metadata_features)¶ Define and apply the architecture of the model to produce scores from transformed features produced by the InteractionModel
Parameters: - train_features (Tensor object) – Dense feature tensor object that is used to compute the model score
- metadata_features (dict of tensor objects) – Dictionary of tensor objects that are not used for training, but can be used for computing loss and metrics
Returns: scores – Tensor object of the score computed by the model
Return type: Tensor object
-
final_activation_op(scores, metadata_features)¶ Define and apply the final activation layer to the scores
Parameters: - scores (Tensor object) – Tensor object of the score computed by the model
- metadata_features (dict of tensor objects) – Dictionary of tensor objects that are not used for training, but can be used for computing loss and metrics
Returns: scores – Tensor object produced by applying the final activation function to the scores computed by the model
Return type: Tensor object
RelevanceScorer¶
-
class
ml4ir.base.model.scoring.scoring_model.RelevanceScorer(model_config: dict, feature_config: ml4ir.base.features.feature_config.FeatureConfig, interaction_model: ml4ir.base.model.scoring.interaction_model.InteractionModel, loss: ml4ir.base.model.losses.loss_base.RelevanceLossBase, file_io: ml4ir.base.io.file_io.FileIO, output_name: str = 'score', logger: Optional[logging.Logger] = None)¶ Bases:
ml4ir.base.model.scoring.scoring_model.ScorerBaseConstructor method for creating a ScorerBase object
Parameters: - model_config (dict) – Dictionary defining the model layer configuration
- feature_config (FeatureConfig object) – FeatureConfig object defining the features and their configurations
- interaction_model (InteractionModel object) – InteractionModel that defines the feature transformation layers on the input model features
- loss (RelevanceLossBase object) – Relevance loss object that defines the final activation layer and the loss function for the model
- file_io (FileIO object) – FileIO object that handles read and write
- output_name (str, optional) – Name of the output that captures the score computed by the model
- logger (Logger, optional) – Logging handler
-
architecture_op(train_features, metadata_features)¶ Define and apply the architecture of the model to produce scores from transformed features produced by the InteractionModel
Parameters: - train_features (Tensor object) – Dense feature tensor object that is used to compute the model score
- metadata_features (dict of tensor objects) – Dictionary of tensor objects that are not used for training, but can be used for computing loss and metrics
Returns: scores – Tensor object of the score computed by the model
Return type: Tensor object
-
final_activation_op(scores, metadata_features)¶ Define and apply the final activation layer to the scores
Parameters: - scores (Tensor object) – Tensor object of the score computed by the model
- metadata_features (dict of tensor objects) – Dictionary of tensor objects that are not used for training, but can be used for computing loss and metrics
Returns: scores – Tensor object produced by applying the final activation function to the scores computed by the model
Return type: Tensor object