tfr.keras.model.Preprocessor
Stay organized with collections
Save and categorize content based on your preferences.
Interface for feature preprocessing.
The Preprocessor
class is an abstract class to implement preprocess
in
ModelBuilder
in tfr.keras.
To be implemented by subclasses:
__call__()
: Contains the logic to preprocess context and example inputs.
Example subclass implementation:
class SimplePreprocessor(Preprocessor):
def __call__(self, context_inputs, example_inputs, mask):
context_features = {
name: tf.math.log1p(
tf.abs(tensor)) for name, tensor in context_inputs.items()
}
example_features = {
name: tf.math.log1p(
tf.abs(tensor)) for name, tensor in example_inputs.items()
}
return context_features, example_features
Methods
__call__
View source
@abc.abstractmethod
__call__(
context_inputs: tfr.keras.model.TensorDict
,
example_inputs: tfr.keras.model.TensorDict
,
mask: tf.Tensor
) -> Tuple[tfr.keras.model.TensorDict
, tfr.keras.model.TensorDict
]
Invokes the Preprocessor
instance.
Args |
context_inputs
|
maps context feature keys to tf.keras.Input .
|
example_inputs
|
maps example feature keys to tf.keras.Input .
|
mask
|
[batch_size, list_size]-tensor of mask for valid examples.
|
Returns |
A tuple of two dicts which map the context and example feature keys to
the corresponding tf.Tensor s.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-08-18 UTC.
[null,null,["Last updated 2023-08-18 UTC."],[],[],null,["# tfr.keras.model.Preprocessor\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L552-L598) |\n\nInterface for feature preprocessing.\n\nThe `Preprocessor` class is an abstract class to implement `preprocess` in\n`ModelBuilder` in tfr.keras.\n\nTo be implemented by subclasses:\n\n- `__call__()`: Contains the logic to preprocess context and example inputs.\n\nExample subclass implementation: \n\n class SimplePreprocessor(Preprocessor):\n\n def __call__(self, context_inputs, example_inputs, mask):\n context_features = {\n name: tf.math.log1p(\n tf.abs(tensor)) for name, tensor in context_inputs.items()\n }\n example_features = {\n name: tf.math.log1p(\n tf.abs(tensor)) for name, tensor in example_inputs.items()\n }\n return context_features, example_features\n\nMethods\n-------\n\n### `__call__`\n\n[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L580-L598) \n\n @abc.abstractmethod\n __call__(\n context_inputs: ../../../tfr/keras/model/TensorDict,\n example_inputs: ../../../tfr/keras/model/TensorDict,\n mask: tf.Tensor\n ) -\u003e Tuple[../../../tfr/keras/model/TensorDict, ../../../tfr/keras/model/TensorDict]\n\nInvokes the `Preprocessor` instance.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------------|-------------------------------------------------------------------------------------------------------------|\n| `context_inputs` | maps context feature keys to [`tf.keras.Input`](https://www.tensorflow.org/api_docs/python/tf/keras/Input). |\n| `example_inputs` | maps example feature keys to [`tf.keras.Input`](https://www.tensorflow.org/api_docs/python/tf/keras/Input). |\n| `mask` | \\[batch_size, list_size\\]-tensor of mask for valid examples. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A tuple of two dicts which map the context and example feature keys to the corresponding [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor)s. ||\n\n\u003cbr /\u003e"]]