tfr.keras.model.AbstractModelBuilder
Stay organized with collections
Save and categorize content based on your preferences.
Interface to build a tf.keras.Model
for ranking.
The AbstractModelBuilder
serves as the interface between model building and
training. The training pipeline just calls the build()
method to get the
model constructed in the strategy scope used in the training pipeline, so for
all variables in the model, optimizers, and metrics. See ModelFitPipeline
in
pipeline.py
for example.
The build()
method is to be implemented in a subclass. The simplest example
is just to define everything inside the build function when you define a
tf.keras.Model.
class MyModelBuilder(AbstractModelBuilder):
def build(self) -> tf.keras.Model:
inputs = ...
outputs = ...
return tf.keras.Model(inputs=inputs, outputs=outputs)
The MyModelBuilder
should work with ModelFitPipeline
. To make the model
building more structured for ranking problems, we also define subclasses like
ModelBuilderWithMask
in the following.
Methods
build
View source
@abc.abstractmethod
build() -> tf.keras.Model
The build method to be implemented by a subclass.
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.AbstractModelBuilder\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#L80-L110) |\n\nInterface to build a [`tf.keras.Model`](https://www.tensorflow.org/api_docs/python/tf/keras/Model) for ranking.\n\nThe `AbstractModelBuilder` serves as the interface between model building and\ntraining. The training pipeline just calls the `build()` method to get the\nmodel constructed in the strategy scope used in the training pipeline, so for\nall variables in the model, optimizers, and metrics. See `ModelFitPipeline` in\n`pipeline.py` for example.\n\nThe `build()` method is to be implemented in a subclass. The simplest example\nis just to define everything inside the build function when you define a\ntf.keras.Model. \n\n class MyModelBuilder(AbstractModelBuilder):\n\n def build(self) -\u003e tf.keras.Model:\n inputs = ...\n outputs = ...\n return tf.keras.Model(inputs=inputs, outputs=outputs)\n\nThe `MyModelBuilder` should work with `ModelFitPipeline`. To make the model\nbuilding more structured for ranking problems, we also define subclasses like\n`ModelBuilderWithMask` in the following.\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#L107-L110) \n\n @abc.abstractmethod\n build() -\u003e tf.keras.Model\n\nThe build method to be implemented by a subclass."]]