mlx.data.Stream.sliding_window#
- Stream.sliding_window(self: mlx.data._c.Stream, key: str, size: int, stride: int, dim: int = - 1) mlx.data._c.Stream #
Creates sample by sliding a window over the array at
key
.Commonly used in sequence processing pipelines to deal with very larger documents.
import mlx.data as dx dset = dx.buffer_from_vector({"x": np.arange(10), "unchanged_keys": 10}).to_stream() for sample in dset.sliding_window("x", 3, 2): print(sample["x"]) # prints # [0, 1, 2] # [2, 3, 4] # [4, 5, 6] # [6, 7, 8] # [8, 9]