0
0
TensorFlowml~10 mins

Batching and shuffling in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a TensorFlow dataset from a list of numbers.

TensorFlow
import tensorflow as tf
numbers = [1, 2, 3, 4, 5]
dataset = tf.data.Dataset.[1](numbers)
Drag options to blanks, or click blank then click option'
Afrom_tensor_slices
Bbatch
Cshuffle
Dmap
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'batch' instead of 'from_tensor_slices' will cause an error because batch expects a dataset.
Using 'shuffle' directly on a list is invalid.
2fill in blank
medium

Complete the code to shuffle the dataset with a buffer size of 10.

TensorFlow
dataset = dataset.[1](buffer_size=10)
Drag options to blanks, or click blank then click option'
Amap
Bbatch
Crepeat
Dshuffle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'batch' instead of 'shuffle' will group elements but not shuffle them.
Using 'repeat' will repeat the dataset but not shuffle.
3fill in blank
hard

Fix the error in the code to batch the dataset with batch size 4.

TensorFlow
dataset = dataset.[1](4)
Drag options to blanks, or click blank then click option'
Abatch
Bshuffle
Cmap
Drepeat
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'shuffle' instead of 'batch' will shuffle elements but not group them.
Using 'map' applies a function but does not batch.
4fill in blank
hard

Fill both blanks to create a dataset from a list, shuffle it with buffer size 5.

TensorFlow
dataset = tf.data.Dataset.[1](data).[2](buffer_size=5)
Drag options to blanks, or click blank then click option'
Afrom_tensor_slices
Bbatch
Cshuffle
Drepeat
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'batch' before 'shuffle' will cause errors if the dataset is not created first.
Using 'repeat' instead of 'shuffle' will not randomize the data.
5fill in blank
hard

Fill all three blanks to create a dataset from a list, shuffle with buffer size 8, and batch with size 3.

TensorFlow
dataset = tf.data.Dataset.[1](items).[2](buffer_size=8).[3](3)
Drag options to blanks, or click blank then click option'
Afrom_tensor_slices
Bshuffle
Cbatch
Drepeat
Attempts:
3 left
💡 Hint
Common Mistakes
Changing the order of methods can cause unexpected behavior.
Using 'repeat' instead of 'shuffle' will not randomize the data.