0
0
PyTorchml~10 mins

Dataset class (custom datasets) 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 import the Dataset class from PyTorch.

PyTorch
from torch.utils.data import [1]
Drag options to blanks, or click blank then click option'
ADataLoader
BModule
CTensor
DDataset
Attempts:
3 left
💡 Hint
Common Mistakes
Importing DataLoader instead of Dataset
Using Module which is for models, not datasets
2fill in blank
medium

Complete the code to define the __len__ method that returns the dataset size.

PyTorch
def __len__(self):
    return [1]
Drag options to blanks, or click blank then click option'
Alen(self.data)
Bself.length
Cself.data_size
Dself.size
Attempts:
3 left
💡 Hint
Common Mistakes
Returning an undefined attribute like self.length
Returning a fixed number instead of dataset length
3fill in blank
hard

Fix the error in the __getitem__ method to return the correct data sample.

PyTorch
def __getitem__(self, idx):
    sample = self.data[[1]]
    return sample
Drag options to blanks, or click blank then click option'
Aself.idx
Bindex
Cidx
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not defined in the method
Using self.idx which is not defined
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 characters.

PyTorch
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length
Using wrong comparison operator like <
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values for items with positive values.

PyTorch
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using k instead of k.upper() for keys
Using wrong comparison operator like <=
Using k instead of v for values