Skip to content

keras.utils.timeseries_dataset_from_array example bugs #21305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zhangpanzhan opened this issue May 20, 2025 · 1 comment
Open

keras.utils.timeseries_dataset_from_array example bugs #21305

zhangpanzhan opened this issue May 20, 2025 · 1 comment
Assignees
Labels

Comments

@zhangpanzhan
Copy link

  1. if you refer to documentary of timeseries_dataset_from_array, there is an example similarly like this ( I changed parameter for quickly proof):
data = np.arange(10)
x = data[:-3] # x will be [0, 1, 2, 3, 4, 5, 6]
y = data[3:]  # y will be [3, 4, 5, 6, 7, 8, 9]
batch_data = timeseries_dataset_from_array(x, y, 3, 1)
for input, target in batch_data:
    print(input, target)

It will create samples like [0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5],[4, 5, 6] with labels [3, 4, 5, 6, 7].
However, obviously, it misses samples [5, 6, 7], [6, 7, 8] with lables [8, 9].

Image

The api may expected to have the x, and y with same length, but it will miss some samples.
However, if you feed x with data, and y, the output should be correct.
That means, the example 2 in this api should be changed!!!

Image
@dhantule
Copy link
Contributor

dhantule commented May 20, 2025

Hi @zhangpanzhan, Thanks for reporting this.

After generating the sequence [4, 5, 6] which corresponds to target 7, there are no more valid sequences of length 3 that can be extracted from x, so there are no sequences generated for target 8 and 9. So, when you replace x with data, now there are enough sequences that can be generated for the given targets.

I have tested Example 2 and it's working fine in this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants