Skip to content

Shuffling || Global or operational seed #84

Answered by mrdbourke
tarmas99 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey Samrat,

Looks like the operation seed is getting reset every time you call the for loop.

I'd try running the different combinations of the seed you've run without the for loop.

For example:

# Cell 1
import tensorflow as tf
tf.random.set_seed(42)
A = tf.reshape(tf.range(9)+1, [3, 3])
tf.random.shuffle(A)

>>> <tf.Tensor: shape=(3, 3), dtype=int32, numpy=
array([[4, 5, 6],
       [7, 8, 9],
       [1, 2, 3]], dtype=int32)>
# Cell 2
import tensorflow as tf
tf.random.set_seed(42)
A = tf.reshape(tf.range(9)+1, [3, 3])
tf.random.shuffle(A)

<tf.Tensor: shape=(3, 3), dtype=int32, numpy=
array([[4, 5, 6],
       [7, 8, 9],
       [1, 2, 3]], dtype=int32)>

You should notice the same outputs …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mrdbourke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants