# tfr.keras.model.PreprocessorWithSpec

<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#L601-L665) |

Preprocessing inputs with provided spec.

Inherits From: [`Preprocessor`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/model/Preprocessor)

    tfr.keras.model.PreprocessorWithSpec(
        preprocess_spec: Optional[Dict[str, Callable[[Any], Any]]] = None,
        default_value_spec: Optional[Dict[str, float]] = None
    )

Transformation including KPL or customized transformation like log1p can be
defined and passed in `preprocess_spec` with the following example usage:

    preprocess_spec = {
        **{name: lambda t: tf.math.log1p(t * tf.sign(t)) * tf.sign(t)
           for name in example_feature_spec.keys()},
        **{name: tf.reduce_mean(
            tf.keras.layers.Embedding(input_dim=10, output_dim=4)(x), axis=-2)
           for name in context_feature_spec.keys()}
    }
    preprocessor = PreprocessorWithSpec(preprocess_spec)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `preprocess_spec` | maps a feature key to a callable to preprocess a feature. Only include those features that need preprocessing. |
| `default_value_spec` | maps a feature key to a default value to convert a RaggedTensor to Tensor. Default to 0. if not specified. |

<br />

## Methods

### `__call__`

[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L635-L665)

    __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]

See `Preprocessor`.