Interaction Model

InteractionModel

class ml4ir.base.model.scoring.interaction_model.InteractionModel(feature_config: ml4ir.base.features.feature_config.FeatureConfig, tfrecord_type: str, feature_layer_keys_to_fns: dict = {}, max_sequence_size: int = 0, file_io: ml4ir.base.io.file_io.FileIO = None, **kwargs)

Bases: keras.engine.training.Model

InteractionModel class that defines tensorflow layers that act on input features to convert them into numeric features to be fed into further neural network layers

Constructor for instantiating a base InteractionModel

Parameters:
  • feature_config (FeatureConfig object) – FeatureConfig object that defines list of model features and the feature transformation functions to be used on each
  • tfrecord_type ({"example", "sequence_example"}) – Type of TFRecord protobuf being used for model training
  • feature_layer_keys_to_fns (dict) – Dictionary of custom feature transformation functions to be applied on the input features
  • max_sequence_size (int, optional) – Maximum size of the sequence in SequenceExample protobuf
  • file_io (FileIO object) – FileIO object that handles read write operations

UnivariateInteractionModel

class ml4ir.base.model.scoring.interaction_model.UnivariateInteractionModel(feature_config: ml4ir.base.features.feature_config.FeatureConfig, tfrecord_type: str, feature_layer_keys_to_fns: dict = {}, max_sequence_size: int = 0, file_io: ml4ir.base.io.file_io.FileIO = None, **kwargs)

Bases: ml4ir.base.model.scoring.interaction_model.InteractionModel

Keras layer that applies in-graph transformations to input feature tensors

Constructor for instantiating a UnivariateInteractionModel

Parameters:
  • feature_config (FeatureConfig object) – FeatureConfig object that defines list of model features and the feature transformation functions to be used on each
  • tfrecord_type ({"example", "sequence_example"}) – Type of TFRecord protobuf being used for model training
  • feature_layer_keys_to_fns (dict) – Dictionary of custom feature transformation functions to be applied on the input features
  • max_sequence_size (int, optional) – Maximum size of the sequence in SequenceExample protobuf
  • file_io (FileIO object) – FileIO object that handles read write operations
call(inputs, training=None)

Apply the feature transform op to each feature

Parameters:
  • inputs (dict of tensors) – List of tensors that can be found in the FeatureConfig key-d with their node_name
  • training (boolean) – Boolean specifying if the layer is used in training mode or not
Returns:

train: dict of tensors

List of transformed features that are used for training

metadata: dict of tensors

List of transformed features that are used as metadata

Return type:

dict of dict of tensors

feature_layer

class ml4ir.base.features.feature_layer.FeatureLayerMap

Bases: object

Class defining mapping from keys to feature layer functions

Define ml4ir’s predefined feature transformation functions

add_fn(key, fn)

Add custom new function to the FeatureLayerMap

Parameters:
  • key (str) – name of the feature transformation function
  • fn (tf.function) – tensorflow function that transforms input features
add_fns(keys_to_fns_dict)

Add custom new functions to the FeatureLayerMap

Parameters:keykeys_to_fns_dict (dict) – Dictionary with name and definition of custom tensorflow functions that transform input features
get_fns()

Get all feature transformation functions

Returns:Dictionary of feature transformation functions
Return type:dict
get_fn(key)

Get feature transformation function using the key

Parameters:key (str) – Name of the feature transformation function to be fetched
Returns:Feature transformation function
Return type:tf.function
pop_fn(key)

Get feature transformation function using the key and remove from FeatureLayerMap

Parameters:key (str) – Name of the feature transformation function to be fetched
Returns:Feature transformation function
Return type:tf.function