tfr.keras.model.ModelBuilder
Stay organized with collections
Save and categorize content based on your preferences.
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 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")
Args |
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
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()
View source
create_inputs() -> Tuple[tfr.keras.model.TensorDict
, tfr.keras.model.TensorDict
, tf.Tensor]
See ModelBuilderWithMask
.
preprocess
View source
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
View source
score(
context_features: tfr.keras.model.TensorDict
,
example_features: tfr.keras.model.TensorDict
,
mask: tf.Tensor
) -> Union[TensorLike, TensorDict]
See ModelBuilderWithMask
.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-08-18 UTC.
[null,null,["Last updated 2023-08-18 UTC."],[],[],null,["# tfr.keras.model.ModelBuilder\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L316-L395) |\n\nBuilds a [`tf.keras.Model`](https://www.tensorflow.org/api_docs/python/tf/keras/Model).\n\nInherits From: [`ModelBuilderWithMask`](../../../tfr/keras/model/ModelBuilderWithMask), [`AbstractModelBuilder`](../../../tfr/keras/model/AbstractModelBuilder) \n\n tfr.keras.model.ModelBuilder(\n input_creator: Callable[[], Tuple[TensorDict, TensorDict]],\n preprocessor: Callable[[TensorDict, TensorDict, tf.Tensor], Tuple[TensorDict, TensorDict]],\n scorer: Callable[[TensorDict, TensorDict, tf.Tensor], Union[TensorLike, TensorDict]],\n mask_feature_name: str,\n name: Optional[str] = None\n )\n\nThis class implements the `ModelBuilderWithMask` by delegating the class\nbehaviors to the following implementors that can be specified by callers:\n\n- input_creator: A callable or a class like `InputCreator` to implement `create_inputs`.\n- preprocessor: A callable or a class like `Preprocessor` to implement `preprocess`.\n- scorer: A callable or a class like `Scorer` to implement `score`.\n\nUsers can subclass those implementor classes and pass the objects into this\nclass to build a [`tf.keras.Model`](https://www.tensorflow.org/api_docs/python/tf/keras/Model).\n\n#### Example usage:\n\n model_builder = ModelBuilder(\n input_creator=FeatureSpecInputCreator(\n {},\n {\"example_feature_1\": tf.io.FixedLenFeature(\n shape=(1,), dtype=tf.float32, default_value=0.0)}),\n preprocessor=PreprocessorWithSpec(),\n scorer=DNNScorer(hidden_layer_dims=[16]),\n mask_feature_name=\"list_mask\",\n name=\"model_builder\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------------|-------------------------------------------------------------------------|\n| `input_creator` | A callable or a class like `InputCreator` to implement `create_inputs`. |\n| `preprocessor` | A callable or a class like `Preprocessor` to implement `preprocess`. |\n| `scorer` | A callable or a class like `Scorer` to implement `score`. |\n| `mask_feature_name` | name of 2D mask boolean feature. |\n| `name` | (optional) name of the Model. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `build`\n\n[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L285-L313) \n\n build() -\u003e tf.keras.Model\n\nBuilds a Keras Model for Ranking Pipeline.\n\n#### Example usage:\n\n model_builder = SimpleModelBuilder(\n {},\n {\"example_feature_1\": tf.io.FixedLenFeature(\n shape=(1,), dtype=tf.float32, default_value=0.0)},\n \"list_mask\", \"model_builder\")\n model = model_builder.build()\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A [`tf.keras.Model`](https://www.tensorflow.org/api_docs/python/tf/keras/Model). ||\n\n\u003cbr /\u003e\n\n### `create_inputs`\n\n[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L372-L377) \n\n create_inputs() -\u003e Tuple[../../../tfr/keras/model/TensorDict, ../../../tfr/keras/model/TensorDict, tf.Tensor]\n\nSee `ModelBuilderWithMask`.\n\n### `preprocess`\n\n[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L379-L386) \n\n preprocess(\n context_inputs: ../../../tfr/keras/model/TensorDict,\n example_inputs: ../../../tfr/keras/model/TensorDict,\n mask: tf.Tensor\n ) -\u003e Tuple[../../../tfr/keras/model/TensorDict, ../../../tfr/keras/model/TensorDict]\n\nSee `ModelBuilderWithMask`.\n\n### `score`\n\n[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L388-L395) \n\n score(\n context_features: ../../../tfr/keras/model/TensorDict,\n example_features: ../../../tfr/keras/model/TensorDict,\n mask: tf.Tensor\n ) -\u003e Union[TensorLike, TensorDict]\n\nSee `ModelBuilderWithMask`."]]