Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a dataset from a CSV file using TensorFlow.
TensorFlow
dataset = tf.data.experimental.make_csv_dataset('data.csv', batch_size=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using batch size 1 can be very slow.
Using too large batch size can cause memory errors.
✗ Incorrect
The batch size controls how many samples are loaded at once. 32 is a common batch size.
2fill in blank
mediumComplete the code to shuffle the dataset with a buffer size of 1000.
TensorFlow
dataset = dataset.shuffle(buffer_size=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too small buffer size results in poor shuffling.
Using too large buffer size may use too much memory.
✗ Incorrect
Shuffling with a buffer size of 1000 ensures good mixing of data.
3fill in blank
hardFix the error in the code to map a function that normalizes features.
TensorFlow
def normalize(features, label): features = tf.cast(features, tf.float32) / [1] return features, label dataset = dataset.map(normalize)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by 1.0 does not change values.
Dividing by 0.255 is incorrect scaling.
✗ Incorrect
Dividing by 255.0 normalizes pixel values from 0-255 to 0-1.
4fill in blank
hardFill both blanks to batch the dataset and repeat it indefinitely.
TensorFlow
dataset = dataset.[1](batch_size=32).[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling repeat before batch changes the dataset shape.
Using shuffle instead of batch changes data order but not batching.
✗ Incorrect
First batch the dataset, then repeat it indefinitely for training.
5fill in blank
hardFill all three blanks to create a dataset from text files, shuffle, and batch it.
TensorFlow
files = tf.data.Dataset.list_files([1]) dataset = files.interleave(tf.data.TextLineDataset, cycle_length=4) dataset = dataset.[2](buffer_size=1000).[3](batch_size=64)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single file name instead of a pattern.
Batching before shuffling reduces randomness.
✗ Incorrect
Use list_files with a pattern to find text files, then shuffle and batch the dataset.