On this page
tf.data.experimental.group_by_window
A transformation that groups windows of elements by key and reduces them.
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_shapesandself.output_types) to a scalartf.int64tensor. | 
| reduce_func | A function mapping a key and a dataset of up to window_sizeconsecutive elements matching that key to another dataset. | 
| window_size | A tf.int64scalartf.Tensor, representing the number of consecutive elements matching the same key to combine in a single batch, which will be passed toreduce_func. Mutually exclusive withwindow_size_func. | 
| window_size_func | A function mapping a key to a tf.int64scalartf.Tensor, representing the number of consecutive elements matching the same key to combine in a single batch, which will be passed toreduce_func. Mutually exclusive withwindow_size. | 
| Returns | |
|---|---|
| A Datasettransformation function, which can be passed totf.data.Dataset.apply. | 
| Raises | |
|---|---|
| ValueError | if neither or both of { window_size,window_size_func} are passed. | 
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
 https://www.tensorflow.org/versions/r2.4/api_docs/python/tf/data/experimental/group_by_window