View source on GitHub |
Builds a tf.keras.Model
.
Inherits From: ModelBuilderWithMask
, AbstractModelBuilder
tfr.keras.model.ModelBuilder(
input_creator: Callable[[], Tuple[TensorDict, TensorDict]],
preprocessor: Callable[[TensorDict, TensorDict, tf.Tensor], Tuple[TensorDict, TensorDict]],
scorer: Callable[[TensorDict, TensorDict, tf.Tensor], Union[TensorLike, TensorDict]],
mask_feature_name: str,
name: Optional[str] = None
)
This class implements the ModelBuilderWithMask
by delegating the class
behaviors to the following implementors that can be specified by callers:
- input_creator: A callable or a class like
InputCreator
to implementcreate_inputs
. - preprocessor: A callable or a class like
Preprocessor
to implementpreprocess
. - scorer: A callable or a class like
Scorer
to implementscore
.
Users can subclass those implementor classes and pass the objects into this
class to build a tf.keras.Model
.
Example usage:
model_builder = ModelBuilder(
input_creator=FeatureSpecInputCreator(
{},
{"example_feature_1": tf.io.FixedLenFeature(
shape=(1,), dtype=tf.float32, default_value=0.0)}),
preprocessor=PreprocessorWithSpec(),
scorer=DNNScorer(hidden_layer_dims=[16]),
mask_feature_name="list_mask",
name="model_builder")
Methods
build
build() -> tf.keras.Model
Builds a Keras Model for Ranking Pipeline.
Example usage:
model_builder = SimpleModelBuilder(
{},
{"example_feature_1": tf.io.FixedLenFeature(
shape=(1,), dtype=tf.float32, default_value=0.0)},
"list_mask", "model_builder")
model = model_builder.build()
Returns | |
---|---|
A tf.keras.Model .
|
create_inputs
create_inputs() -> Tuple[tfr.keras.model.TensorDict
, tfr.keras.model.TensorDict
, tf.Tensor]
See ModelBuilderWithMask
.
preprocess
preprocess(
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 ModelBuilderWithMask
.
score
score(
context_features: tfr.keras.model.TensorDict
,
example_features: tfr.keras.model.TensorDict
,
mask: tf.Tensor
) -> Union[TensorLike, TensorDict]
See ModelBuilderWithMask
.