tf.data.experimental.group_by_window
Stay organized with collections
Save and categorize content based on your preferences.
A transformation that groups windows of elements by key and reduces them. (deprecated)
tf.data.experimental.group_by_window(
key_func, reduce_func, window_size=None, window_size_func=None
)
This transformation maps each consecutive element in a dataset to a key
using key_func
and groups the elements by key. It then applies
reduce_func
to at most window_size_func(key)
elements matching the same
key. All except the final window for each key will contain
window_size_func(key)
elements; the final window may be smaller.
You may provide either a constant window_size
or a window size determined by
the key through window_size_func
.
Args |
key_func
|
A function mapping a nested structure of tensors
(having shapes and types defined by self.output_shapes and
self.output_types ) to a scalar tf.int64 tensor.
|
reduce_func
|
A function mapping a key and a dataset of up to window_size
consecutive elements matching that key to another dataset.
|
window_size
|
A tf.int64 scalar tf.Tensor , representing the number of
consecutive elements matching the same key to combine in a single
batch, which will be passed to reduce_func . Mutually exclusive with
window_size_func .
|
window_size_func
|
A function mapping a key to a tf.int64 scalar
tf.Tensor , representing the number of consecutive elements matching
the same key to combine in a single batch, which will be passed to
reduce_func . Mutually exclusive with window_size .
|
Raises |
ValueError
|
if neither or both of {window_size , window_size_func } are
passed.
|
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-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.data.experimental.group_by_window\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/data/experimental/ops/grouping.py#L58-L107) |\n\nA transformation that groups windows of elements by key and reduces them. (deprecated)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.data.experimental.group_by_window`](https://www.tensorflow.org/api_docs/python/tf/data/experimental/group_by_window)\n\n\u003cbr /\u003e\n\n tf.data.experimental.group_by_window(\n key_func, reduce_func, window_size=None, window_size_func=None\n )\n\n| **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use [`tf.data.Dataset.group_by_window(...)`](../../../tf/data/Dataset#group_by_window).\n\nThis transformation maps each consecutive element in a dataset to a key\nusing `key_func` and groups the elements by key. It then applies\n`reduce_func` to at most `window_size_func(key)` elements matching the same\nkey. All except the final window for each key will contain\n`window_size_func(key)` elements; the final window may be smaller.\n\nYou may provide either a constant `window_size` or a window size determined by\nthe key through `window_size_func`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `key_func` | A function mapping a nested structure of tensors (having shapes and types defined by `self.output_shapes` and `self.output_types`) to a scalar [`tf.int64`](../../../tf#int64) tensor. |\n| `reduce_func` | A function mapping a key and a dataset of up to `window_size` consecutive elements matching that key to another dataset. |\n| `window_size` | A [`tf.int64`](../../../tf#int64) scalar [`tf.Tensor`](../../../tf/Tensor), representing the number of consecutive elements matching the same key to combine in a single batch, which will be passed to `reduce_func`. Mutually exclusive with `window_size_func`. |\n| `window_size_func` | A function mapping a key to a [`tf.int64`](../../../tf#int64) scalar [`tf.Tensor`](../../../tf/Tensor), representing the number of consecutive elements matching the same key to combine in a single batch, which will be passed to `reduce_func`. Mutually exclusive with `window_size`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Dataset` transformation function, which can be passed to [`tf.data.Dataset.apply`](../../../tf/data/Dataset#apply). ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------------------------------------------------------|\n| `ValueError` | if neither or both of {`window_size`, `window_size_func`} are passed. |\n\n\u003cbr /\u003e"]]