0
0
PyTorchml~10 mins

Why generative models create data in PyTorch - Test Your Understanding

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

Complete the code to define a simple generative model class in PyTorch.

PyTorch
import torch.nn as nn

class SimpleGenerator(nn.Module):
    def __init__(self):
        super(SimpleGenerator, self).__init__()
        self.model = nn.Sequential(
            nn.Linear(100, 256),
            nn.ReLU(),
            nn.Linear(256, 784),
            nn.Tanh()
        )

    def forward(self, [1]):
        return self.model(x)
Drag options to blanks, or click blank then click option'
Anoise
Binput
Cdata
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the method parameters.
Forgetting to include the input parameter in the forward method.
2fill in blank
medium

Complete the code to generate fake data from random noise using the generator model.

PyTorch
import torch

noise = torch.randn(16, 100)
fake_data = generator.[1](noise)
Drag options to blanks, or click blank then click option'
Agenerate
Bpredict
C__call__
Dforward
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call a non-existent 'generate' or 'predict' method.
Using 'forward' method directly instead of calling the model.
3fill in blank
hard

Fix the error in the training loop where the generator tries to create data.

PyTorch
for epoch in range(5):
    noise = torch.randn(32, 100)
    fake_data = generator.[1](noise)
    # further training steps...
Drag options to blanks, or click blank then click option'
Aforward
B__call__
Cgenerate
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a method that does not exist on the model.
Using 'forward' method directly instead of calling the model.
4fill in blank
hard

Fill both blanks to create a dictionary of generated images with their indices.

PyTorch
generated_images = {i: fake_data[1] for i in range(10) if i [2] 5}
Drag options to blanks, or click blank then click option'
A[i]
B(i)
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for indexing.
Using the wrong comparison operator in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary of generated images with their pixel sums greater than 1000.

PyTorch
filtered_images = {i: fake_data[1] for i in range(20) if fake_data[2].sum() [3] 1000}
Drag options to blanks, or click blank then click option'
A[i]
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for indexing.
Using '<' instead of '>' in the condition.