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



View source

Invokes the Preprocessor instance.

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.

A tuple of two dicts which map the context and example feature keys to the corresponding tf.Tensors.