transformers4rec.tf.utils package

Submodules

transformers4rec.tf.utils.repr_utils module

transformers4rec.tf.utils.repr_utils.dict_wrapper_repr(self)[source]
transformers4rec.tf.utils.repr_utils.list_wrapper_repr(self)[source]
transformers4rec.tf.utils.repr_utils.layer_repr(self)[source]
transformers4rec.tf.utils.repr_utils.layer_repr_no_children(self)[source]
transformers4rec.tf.utils.repr_utils.dense_extra_repr(self)[source]

transformers4rec.tf.utils.schema_utils module

transformers4rec.tf.utils.schema_utils.random_data_from_schema(schema: merlin_standard_lib.schema.schema.Schema, num_rows: int, max_session_length: Optional[int] = None, min_session_length: int = 5)Dict[str, tensorflow.python.framework.ops.Tensor][source]

transformers4rec.tf.utils.testing_utils module

transformers4rec.tf.utils.testing_utils.mark_run_eagerly_modes(*args, **kwargs)[source]
transformers4rec.tf.utils.testing_utils.assert_body_works_in_model(data, inputs, body, run_eagerly)[source]
transformers4rec.tf.utils.testing_utils.assert_loss_and_metrics_are_valid(input, inputs, targets, call_body=True)[source]
transformers4rec.tf.utils.testing_utils.assert_serialization(layer)[source]

transformers4rec.tf.utils.tf_utils module

class transformers4rec.tf.utils.tf_utils.LossMixin[source]

Bases: abc.ABC

Mixin to use for Keras Layers that can calculate a loss.

compute_loss(inputs: Union[tensorflow.python.framework.ops.Tensor, Dict[str, tensorflow.python.framework.ops.Tensor]], targets: Union[tensorflow.python.framework.ops.Tensor, Dict[str, tensorflow.python.framework.ops.Tensor]], compute_metrics=True, training: bool = False, **kwargs)tensorflow.python.framework.ops.Tensor[source]

Compute the loss on a batch of data.

Parameters
class transformers4rec.tf.utils.tf_utils.MetricsMixin[source]

Bases: abc.ABC

Mixin to use for Keras Layers that can calculate metrics.

calculate_metrics(inputs: Union[tensorflow.python.framework.ops.Tensor, Dict[str, tensorflow.python.framework.ops.Tensor]], targets: Union[tensorflow.python.framework.ops.Tensor, Dict[str, tensorflow.python.framework.ops.Tensor]], mode: str = 'val', forward=True, **kwargs)Dict[str, Union[Dict[str, tensorflow.python.framework.ops.Tensor], tensorflow.python.framework.ops.Tensor]][source]

Calculate metrics on a batch of data, each metric is stateful and this updates the state.

The state of each metric can be retrieved by calling the metric_results method.

Parameters
  • inputs (Union[tf.Tensor, TabularData]) – TODO

  • targets (Union[tf.Tensor, TabularData]) – TODO

  • forward (bool, default True) –

  • mode (str, default="val") –

metric_results(mode: Optional[str] = None)Dict[str, Union[float, tensorflow.python.framework.ops.Tensor]][source]

Returns the current state of each metric.

The state is typically updated each batch by calling the calculate_metrics method.

Parameters

mode (str, default="val") –

Returns

Return type

Dict[str, Union[float, tf.Tensor]]

reset_metrics()[source]

Reset all metrics.

transformers4rec.tf.utils.tf_utils.get_output_sizes_from_schema(schema, batch_size=0, max_sequence_length=None)[source]
transformers4rec.tf.utils.tf_utils.calculate_batch_size_from_input_shapes(input_shapes)[source]
transformers4rec.tf.utils.tf_utils.get_tf_main_layer(hf_model)[source]

Extract serializable custom keras layer TF*MainLayer from the HF model

transformers4rec.tf.utils.tf_utils.maybe_serialize_keras_objects(self, config, maybe_serialize_keys)[source]
transformers4rec.tf.utils.tf_utils.maybe_deserialize_keras_objects(config, to_deserialize, deserialize_fn=<function deserialize_keras_object>)[source]
transformers4rec.tf.utils.tf_utils.extract_topk(ks, scores, labels)[source]
transformers4rec.tf.utils.tf_utils.tranform_label_to_onehot(labels, vocab_size)[source]
transformers4rec.tf.utils.tf_utils.create_output_placeholder(scores, ks)[source]
transformers4rec.tf.utils.tf_utils.gather_torch_like(labels, indices, max_k)[source]

Module contents