Interaction Model¶
InteractionModel¶
-
class
ml4ir.base.model.scoring.interaction_model.InteractionModel¶ Bases:
objectInteractionModel class that defines tensorflow layers that act on input features to convert them into numeric features to be fed into further neural network layers
-
feature_layer_op(inputs: Dict[str, tensorflow.python.keras.engine.input_layer.Input])¶ Convert input tensorflow features into numeric train features and metadata features by applying respective feature transformation functions as specified in the FeatureConfig
Parameters: inputs (dict) – Dictionary of the inputs to the tensorflow keras model Returns: - train_features (dict) – Dict of feature tensors that are used for training
- metadata_features (dict) – Dictionary of feature tensors that can be used for computing custom metrics and losses
-
transform_features_op(train_features, metadata_features)¶ Convert train and metadata features which have feature layer functions applied to them into dense numeric tensors
Parameters: inputs (dict) – Dictionary of the inputs to the tensorflow keras model Returns: - train_features (tf.Tensor) – Dense tensor object that is used for training
- metadata_features (dict) – Dictionary of feature tensors that can be used for computing custom metrics and losses
-
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)¶ Bases:
ml4ir.base.model.scoring.interaction_model.InteractionModelDefines an interaction model that configures feature layer operations on individual features
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
-
feature_layer_op(inputs: Dict[str, tensorflow.python.keras.engine.input_layer.Input])¶ Convert input tensorflow features into numeric train features and metadata features by applying respective feature transformation functions as specified in the FeatureConfig
Parameters: inputs (dict) – Dictionary of the inputs to the tensorflow keras model Returns: - train_features (dict) – Dict of feature tensors that are used for training
- metadata_features (dict) – Dictionary of feature tensors that can be used for computing custom metrics and losses
-
transform_features_op(train_features: Dict[str, tensorflow.python.framework.ops.Tensor], metadata_features: Dict[str, tensorflow.python.framework.ops.Tensor])¶ Convert train and metadata features which have feature layer functions applied to them into dense numeric tensors. Sorts the features by name and concats the individual features into a dense tensor.
Parameters: inputs (dict) – Dictionary of the inputs to the tensorflow keras model Returns: - train_features (tf.Tensor) – Dense tensor object that is used for training
- metadata_features (dict) – Dictionary of feature tensors that can be used for computing custom metrics and losses
feature_layer¶
-
class
ml4ir.base.features.feature_layer.FeatureLayerMap¶ Bases:
objectClass 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
-
-
ml4ir.base.features.feature_layer.define_feature_layer(feature_config: ml4ir.base.features.feature_config.FeatureConfig, tfrecord_type: str, feature_layer_map: ml4ir.base.features.feature_layer.FeatureLayerMap, file_io: ml4ir.base.io.file_io.FileIO)¶ Defines a feature layer function that works on keras.Inputs
Parameters: - feature_config (FeatureConfig object) – FeatureConfig object that defines the feature transformation function to be applied to each feature
- tfrecord_type ({"example", "sequence_example"}) – String defining the TFRecord type of the data
- feature_layer_map (FeatureLayerMap) – FeatureLayerMap object mapping custom function names to function definition
Returns: - tensorflow op that is the feature layer by collecting all the
- feature transformation functions assigned to the respective
- keras.Inputs features as specified by the FeatureConfig
Notes
Use feature_layer_map to define custom functions when using ml4ir as a library