tfr.keras.pipeline.BaseDatasetBuilder
Stay organized with collections
Save and categorize content based on your preferences.
Builds datasets from feature specs.
Inherits From: AbstractDatasetBuilder
tfr.keras.pipeline.BaseDatasetBuilder(
context_feature_spec: Dict[str, Union[tf.io.FixedLenFeature, tf.io.VarLenFeature, tf.io.
RaggedFeature]],
example_feature_spec: Dict[str, Union[tf.io.FixedLenFeature, tf.io.VarLenFeature, tf.io.
RaggedFeature]],
training_only_example_spec: Dict[str, Union[tf.io.FixedLenFeature, tf.io.VarLenFeature, tf.io.
RaggedFeature]],
mask_feature_name: str,
hparams: tfr.keras.pipeline.DatasetHparams
,
training_only_context_spec: Optional[Dict[str, Union[tf.io.FixedLenFeature, tf.io.VarLenFeature, tf.io.
RaggedFeature]]] = None
)
The BaseDatasetBuilder
class is an abstract class inherit from
AbstractDatasetBuilder
to serve training and validation datasets and
signatures for training ModelFitPipeline
.
To be implemented by subclasses:
_features_and_labels()
: Contains the logic to map a dict of tensors of
dataset to feature tensors and label tensors.
Example subclass implementation:
class SimpleDatasetBuilder(BaseDatasetBuilder):
def _features_and_labels(self, features):
label = features.pop("utility")
return features, label
Args |
context_feature_spec
|
Maps context (aka, query) names to feature specs.
|
example_feature_spec
|
Maps example (aka, document) names to feature specs.
|
training_only_example_spec
|
Feature specs used for training only like
labels and per-example weights.
|
mask_feature_name
|
If set, populates the feature dictionary with this name
and the coresponding value is a tf.bool Tensor of shape [batch_size,
list_size] indicating the actual example is padded or not.
|
hparams
|
A dict containing model hyperparameters.
|
training_only_context_spec
|
Feature specs used for training only per-list
weights.
|
Methods
build_signatures
View source
build_signatures(
model: tf.keras.Model
) -> Any
See AbstractDatasetBuilder
.
build_train_dataset
View source
build_train_dataset() -> tf.data.Dataset
See AbstractDatasetBuilder
.
build_valid_dataset
View source
build_valid_dataset() -> tf.data.Dataset
See AbstractDatasetBuilder
.
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.pipeline.BaseDatasetBuilder\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/pipeline.py#L866-L1007) |\n\nBuilds datasets from feature specs.\n\nInherits From: [`AbstractDatasetBuilder`](../../../tfr/keras/pipeline/AbstractDatasetBuilder) \n\n tfr.keras.pipeline.BaseDatasetBuilder(\n context_feature_spec: Dict[str, Union[tf.io.FixedLenFeature, tf.io.VarLenFeature, tf.io.\n RaggedFeature]],\n example_feature_spec: Dict[str, Union[tf.io.FixedLenFeature, tf.io.VarLenFeature, tf.io.\n RaggedFeature]],\n training_only_example_spec: Dict[str, Union[tf.io.FixedLenFeature, tf.io.VarLenFeature, tf.io.\n RaggedFeature]],\n mask_feature_name: str,\n hparams: ../../../tfr/keras/pipeline/DatasetHparams,\n training_only_context_spec: Optional[Dict[str, Union[tf.io.FixedLenFeature, tf.io.VarLenFeature, tf.io.\n RaggedFeature]]] = None\n )\n\nThe `BaseDatasetBuilder` class is an abstract class inherit from\n`AbstractDatasetBuilder` to serve training and validation datasets and\nsignatures for training `ModelFitPipeline`.\n\nTo be implemented by subclasses:\n\n- `_features_and_labels()`: Contains the logic to map a dict of tensors of dataset to feature tensors and label tensors.\n\nExample subclass implementation: \n\n class SimpleDatasetBuilder(BaseDatasetBuilder):\n\n def _features_and_labels(self, features):\n label = features.pop(\"utility\")\n return features, label\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `context_feature_spec` | Maps context (aka, query) names to feature specs. |\n| `example_feature_spec` | Maps example (aka, document) names to feature specs. |\n| `training_only_example_spec` | Feature specs used for training only like labels and per-example weights. |\n| `mask_feature_name` | If set, populates the feature dictionary with this name and the coresponding value is a [`tf.bool`](https://www.tensorflow.org/api_docs/python/tf#bool) Tensor of shape \\[batch_size, list_size\\] indicating the actual example is padded or not. |\n| `hparams` | A dict containing model hyperparameters. |\n| `training_only_context_spec` | Feature specs used for training only per-list weights. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `build_signatures`\n\n[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/pipeline.py#L1001-L1007) \n\n build_signatures(\n model: tf.keras.Model\n ) -\u003e Any\n\nSee `AbstractDatasetBuilder`.\n\n### `build_train_dataset`\n\n[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/pipeline.py#L984-L990) \n\n build_train_dataset() -\u003e tf.data.Dataset\n\nSee `AbstractDatasetBuilder`.\n\n### `build_valid_dataset`\n\n[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/pipeline.py#L992-L999) \n\n build_valid_dataset() -\u003e tf.data.Dataset\n\nSee `AbstractDatasetBuilder`."]]