0
0
PyTorchml~10 mins

Batch size and shuffling in PyTorch - 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 DataLoader with batch size 32.

PyTorch
loader = DataLoader(dataset, batch_size=[1])
Drag options to blanks, or click blank then click option'
A64
B32
C16
D128
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a batch size too small or too large for the example.
Confusing batch size with dataset size.
2fill in blank
medium

Complete the code to enable shuffling of data in the DataLoader.

PyTorch
loader = DataLoader(dataset, batch_size=32, shuffle=[1])
Drag options to blanks, or click blank then click option'
A0
BFalse
CNone
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting shuffle to False or None, which disables shuffling.
Using 0 instead of a boolean value.
3fill in blank
hard

Fix the error in the DataLoader creation by choosing the correct batch size type.

PyTorch
loader = DataLoader(dataset, batch_size=[1], shuffle=True)
Drag options to blanks, or click blank then click option'
A'32'
BNone
C32
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like '32' instead of integer 32.
Passing None or True as batch size.
4fill in blank
hard

Fill both blanks to create a DataLoader with batch size 64 and shuffling enabled.

PyTorch
loader = DataLoader(dataset, batch_size=[1], shuffle=[2])
Drag options to blanks, or click blank then click option'
A64
BTrue
CFalse
D32
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up batch size and shuffle values.
Using False for shuffle when shuffling is needed.
5fill in blank
hard

Fill all three blanks to create a DataLoader with batch size 16, shuffling enabled, and drop_last set to True.

PyTorch
loader = DataLoader(dataset, batch_size=[1], shuffle=[2], drop_last=[3])
Drag options to blanks, or click blank then click option'
A16
BTrue
CFalse
D32
Attempts:
3 left
💡 Hint
Common Mistakes
Setting drop_last to False when dropping last batch is needed.
Using wrong types for parameters.