0
0
TensorFlowml~10 mins

Dataset from files 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 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'
A1
B10
C100
D32
Attempts:
3 left
💡 Hint
Common Mistakes
Using batch size 1 can be very slow.
Using too large batch size can cause memory errors.
2fill in blank
medium

Complete 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'
A1000
B100
C10
D5000
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.
3fill in blank
hard

Fix 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'
A255.0
B1.0
C100.0
D0.255
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by 1.0 does not change values.
Dividing by 0.255 is incorrect scaling.
4fill in blank
hard

Fill 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'
Abatch
Bshuffle
Crepeat
Dmap
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.
5fill in blank
hard

Fill 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'
A'data/*.txt'
Bshuffle
Cbatch
D'data.csv'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single file name instead of a pattern.
Batching before shuffling reduces randomness.