tfr.keras.pipeline.SimpleDatasetBuilder
Stay organized with collections
Save and categorize content based on your preferences.
Builds datasets from feature specs with a single label spec.
Inherits From: BaseDatasetBuilder
, AbstractDatasetBuilder
tfr.keras.pipeline.SimpleDatasetBuilder(
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]],
mask_feature_name: str,
label_spec: Tuple[str, tf.io.FixedLenFeature],
hparams: tfr.keras.pipeline.DatasetHparams
,
sample_weight_spec: Optional[Tuple[str, tf.io.FixedLenFeature]] = None
)
This supports a single dataset with a single label, which is supposed to be a
dense Tensor.
Example usage:
context_feature_spec = {}
example_feature_spec = {
"example_feature_1": tf.io.FixedLenFeature(
shape=(1,), dtype=tf.float32, default_value=0.0)
}
mask_feature_name = "list_mask"
label_spec = {
"utility": tf.io.FixedLenFeature(
shape=(1,), dtype=tf.float32, default_value=0.0)
}
dataset_hparams = DatasetHparams(
train_input_pattern="train.dat",
valid_input_pattern="valid.dat",
train_batch_size=128,
valid_batch_size=128)
dataset_builder = SimpleDatasetBuilder(
context_feature_spec,
example_feature_spec,
mask_feature_name,
label_spec,
dataset_hparams)
Args |
context_feature_spec
|
Maps context (aka, query) names to feature specs.
|
example_feature_spec
|
Maps example (aka, document) names to feature specs.
|
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.
|
label_spec
|
A tuple of the label name and a tf.io.FixedLenFeature spec, or
a dict that maps task name to label spec in multi-task setting.
|
hparams
|
A dict containing model hyperparameters.
|
sample_weight_spec
|
Feature spec for per-example weight.
|
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.SimpleDatasetBuilder\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#L1026-L1117) |\n\nBuilds datasets from feature specs with a single label spec.\n\nInherits From: [`BaseDatasetBuilder`](../../../tfr/keras/pipeline/BaseDatasetBuilder), [`AbstractDatasetBuilder`](../../../tfr/keras/pipeline/AbstractDatasetBuilder) \n\n tfr.keras.pipeline.SimpleDatasetBuilder(\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 mask_feature_name: str,\n label_spec: Tuple[str, tf.io.FixedLenFeature],\n hparams: ../../../tfr/keras/pipeline/DatasetHparams,\n sample_weight_spec: Optional[Tuple[str, tf.io.FixedLenFeature]] = None\n )\n\nThis supports a single dataset with a single label, which is supposed to be a\ndense Tensor.\n\n#### Example usage:\n\n context_feature_spec = {}\n example_feature_spec = {\n \"example_feature_1\": tf.io.FixedLenFeature(\n shape=(1,), dtype=tf.float32, default_value=0.0)\n }\n mask_feature_name = \"list_mask\"\n label_spec = {\n \"utility\": tf.io.FixedLenFeature(\n shape=(1,), dtype=tf.float32, default_value=0.0)\n }\n dataset_hparams = DatasetHparams(\n train_input_pattern=\"train.dat\",\n valid_input_pattern=\"valid.dat\",\n train_batch_size=128,\n valid_batch_size=128)\n dataset_builder = SimpleDatasetBuilder(\n context_feature_spec,\n example_feature_spec,\n mask_feature_name,\n label_spec,\n dataset_hparams)\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| `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| `label_spec` | A tuple of the label name and a tf.io.FixedLenFeature spec, or a dict that maps task name to label spec in multi-task setting. |\n| `hparams` | A dict containing model hyperparameters. |\n| `sample_weight_spec` | Feature spec for per-example weight. |\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`."]]