tensorflow / tensorflow/datasets
.take after .shuffle doesn't work as expected
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 1.6k
- Avg merge
- 3h 54m
- Merged PRs (30d)
- 1
Description
Performing .take(1).repeat() after .shuffle(N) returns N different elements.
Reproduction instructions
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3, 4])
dataset = dataset.shuffle(4)
dataset = dataset.take(1)
dataset = dataset.repeat()
dataset = dataset.take(10)
for x in dataset:
print(x)
This will print 10 different, random integers in the range 1 - 4.
Expected behavior
I would have expected this to print only a single unique integer. It appears the early .shuffle interferes with the later .take, which is very counterintuitive.
See this colab:
https://colab.research.google.com/drive/1UYu3TyzMd2nPs19YyNrViFQZxfSyw8WR?usp=sharing
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Python reproduction with tf.data.Dataset, shuffle(4), take(1), repeat(), and take(10), then compare the output with the linked Colab. Trace how these chained operations interact and confirm that the completed behavior yields one repeated value rather than ten different elements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100