View source on GitHub |
Preprocessing inputs with provided spec.
Inherits From: 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)
Methods
__call__
__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
]
See Preprocessor
.