tfr.keras.model.ModelBuilder

Builds a tf.keras.Model.

Inherits From: ModelBuilderWithMask, AbstractModelBuilder

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 implement create_inputs.
  • preprocessor: A callable or a class like Preprocessor to implement preprocess.
  • scorer: A callable or a class like Scorer to implement score.

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")

input_creator A callable or a class like InputCreator to implement create_inputs.
preprocessor A callable or a class like Preprocessor to implement preprocess.
scorer A callable or a class like Scorer to implement score.
mask_feature_name name of 2D mask boolean feature.
name (optional) name of the Model.

Methods

build

View source

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

View source

See ModelBuilderWithMask.

preprocess

View source

See ModelBuilderWithMask.

score

View source

See ModelBuilderWithMask.