Closed awesomepgm closed 2 years ago
Thanks for spotting this mistake @awesomepgm! I changed to and added you to contributors section.
# we'll just train on 5,000 and use 1,000 for test
# shuffle, but only once (reshuffle_each_iteration=False) so
# we lock in which are train/test/val
shuffled_data = data.shuffle(7000, reshuffle_each_iteration=False)
test_set = shuffled_data.take(1000)
valid_set = shuffled_data.skip(1000).take(1000)
train_set = shuffled_data.skip(2000).take(5000)
Sorry but if you don't mind can you change my name? I forgot I did not have my real name displayed on my Github page. It should now be there, but it is Parsa Pourghasem. I also wanted to mention that I have not tested it, but it seems to me that chapter 8, "Graph Neural Networks", might also have the same problem as it has the same shuffling at 8.12.
Here is the offending code:
data = tf.data.Dataset.from_generator(
generator,
output_signature=(
tf.TensorSpec(shape=(None, 2), dtype=tf.float32),
tf.TensorSpec(shape=(), dtype=tf.int32),
),
).shuffle(1000)
# The shuffling above is really important because this dataset is in order of labels!
val_data = data.take(100)
test_data = data.skip(100).take(100)
train_data = data.skip(200)
Thanks @awesomepgm! I looked through it too, don't think I have any more examples like that. Got this one fixed too and updated your name
The data shuffling done by TensorFlow seems to randomize the data each time its elements are accessed. This means that there are many duplicates between the train and test sets which could cause issues with the evaluation of the model. I apologize if this was intentional, but I can't see any way in which this is beneficial.
The offending code:
How I tested it:
I ran all of the code from the notebook up to the offending code. I looped over each element pair of the test and train sets and checked if they were identical. There were many duplicates.
Testing code:
One output:
As you can see, the first and second outputs are the same despite one coming from the train set and the other from the test set. There are many more than just this one (on the scale of hundreds). Please let me know if I am missing something.