# tfr.keras.model.Preprocessor

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L552-L598) |

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](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L580-L598)

    @abc.abstractmethod
    __call__(
        context_inputs: https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/model/TensorDict,
        example_inputs: https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/model/TensorDict,
        mask: tf.Tensor
    ) -> Tuple[https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/model/TensorDict, https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/model/TensorDict]

Invokes the `Preprocessor` instance.

<br />

<br />

<br />

| Args ||
|---|---|
| `context_inputs` | maps context feature keys to [`tf.keras.Input`](https://www.tensorflow.org/api_docs/python/tf/keras/Input). |
| `example_inputs` | maps example feature keys to [`tf.keras.Input`](https://www.tensorflow.org/api_docs/python/tf/keras/Input). |
| `mask` | \[batch_size, list_size\]-tensor of mask for valid examples. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| 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. ||

<br />