View source on GitHub |
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__
@abc.abstractmethod
__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
]
Invokes the Preprocessor
instance.
Args | |
---|---|
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. |
Returns | |
---|---|
A tuple of two dicts which map the context and example feature keys to
the corresponding tf.Tensor s.
|