tfr.keras.model.PreprocessorWithSpec

Preprocessing inputs with provided spec.

Inherits From: Preprocessor

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)

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.

Methods

__call__

View source

See Preprocessor.