tf.keras.utils.unpack_x_y_sample_weight
Stay organized with collections
Save and categorize content based on your preferences.
Unpacks user-provided data tuple.
tf.keras.utils.unpack_x_y_sample_weight(
data
)
Used in the notebooks
This is a convenience utility to be used when overriding
Model.train_step
, Model.test_step
, or Model.predict_step
.
This utility makes it easy to support data of the form (x,)
,
(x, y)
, or (x, y, sample_weight)
.
Example:
features_batch = ops.ones((10, 5))
labels_batch = ops.zeros((10, 5))
data = (features_batch, labels_batch)
# `y` and `sample_weight` will default to `None` if not provided.
x, y, sample_weight = unpack_x_y_sample_weight(data)
sample_weight is None
True
Args |
data
|
A tuple of the form (x,) , (x, y) , or (x, y, sample_weight) .
|
Returns |
The unpacked tuple, with None s for y and sample_weight if they are
not provided.
|
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. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.utils.unpack_x_y_sample_weight\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/trainers/data_adapters/data_adapter_utils.py#L10-L50) |\n\nUnpacks user-provided data tuple. \n\n tf.keras.utils.unpack_x_y_sample_weight(\n data\n )\n\n### Used in the notebooks\n\n| Used in the guide |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Integrating MinDiff without MinDiffModel](https://www.tensorflow.org/responsible_ai/model_remediation/min_diff/guide/integrating_min_diff_without_min_diff_model) - [Creating a custom Counterfactual Logit Pairing Dataset](https://www.tensorflow.org/responsible_ai/model_remediation/counterfactual/guide/creating_a_custom_counterfactual_dataset) |\n\nThis is a convenience utility to be used when overriding\n[`Model.train_step`](../../../tf/keras/Model#train_step), [`Model.test_step`](../../../tf/keras/Model#test_step), or [`Model.predict_step`](../../../tf/keras/Model#predict_step).\nThis utility makes it easy to support data of the form `(x,)`,\n`(x, y)`, or `(x, y, sample_weight)`.\n\n#### Example:\n\n features_batch = ops.ones((10, 5))\n labels_batch = ops.zeros((10, 5))\n data = (features_batch, labels_batch)\n # `y` and `sample_weight` will default to `None` if not provided.\n x, y, sample_weight = unpack_x_y_sample_weight(data)\n sample_weight is None\n True\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|-------------------------------------------------------------------|\n| `data` | A tuple of the form `(x,)`, `(x, y)`, or `(x, y, sample_weight)`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The unpacked tuple, with `None`s for `y` and `sample_weight` if they are not provided. ||\n\n\u003cbr /\u003e"]]