# tfr.keras.pipeline.BaseDatasetBuilder

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/pipeline.py#L866-L1007) |

Builds datasets from feature specs.

Inherits From: [`AbstractDatasetBuilder`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/pipeline/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: https://www.tensorflow.org/ranking/api_docs/python/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

<br />

<br />

<br />

| ## 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`](https://www.tensorflow.org/api_docs/python/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. |

<br />

## Methods

### `build_signatures`

[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/pipeline.py#L1001-L1007)

    build_signatures(
        model: tf.keras.Model
    ) -> Any

See `AbstractDatasetBuilder`.

### `build_train_dataset`

[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/pipeline.py#L984-L990)

    build_train_dataset() -> tf.data.Dataset

See `AbstractDatasetBuilder`.

### `build_valid_dataset`

[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/pipeline.py#L992-L999)

    build_valid_dataset() -> tf.data.Dataset

See `AbstractDatasetBuilder`.