0
0
PyTorchml~10 mins

Batch normalization (nn.BatchNorm) 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 batch normalization layer for 10 features.

PyTorch
import torch.nn as nn

batch_norm = nn.BatchNorm[1](10)
Drag options to blanks, or click blank then click option'
A3d
B4d
C2d
D1d
Attempts:
3 left
💡 Hint
Common Mistakes
Using BatchNorm2d for 1D features causes shape errors.
Forgetting to specify the number of features.
2fill in blank
medium

Complete the code to apply batch normalization to input tensor x.

PyTorch
output = batch_norm([1])
Drag options to blanks, or click blank then click option'
Ann.BatchNorm1d
Bx
Cbatch_norm
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the layer itself instead of the input tensor.
Using undefined variable names.
3fill in blank
hard

Fix the error in the code to correctly initialize batch normalization for 3D input.

PyTorch
batch_norm = nn.BatchNorm[1](16)
Drag options to blanks, or click blank then click option'
A2d
B1d
C3d
D4d
Attempts:
3 left
💡 Hint
Common Mistakes
Using BatchNorm1d or BatchNorm2d for 3D data causes shape mismatch errors.
Passing 'channels' as a keyword argument instead of 'num_features'.
4fill in blank
hard

Fill both blanks to create a batch normalization layer and apply it to input tensor x.

PyTorch
batch_norm = nn.BatchNorm[1]([2])
output = batch_norm(x)
Drag options to blanks, or click blank then click option'
A2d
B1d
C10
D16
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing BatchNorm1d with 2D data.
Using wrong number of features.
5fill in blank
hard

Fill all three blanks to create a batch normalization layer, apply it to x, and get the mean of the output.

PyTorch
batch_norm = nn.BatchNorm[1]([2])
output = batch_norm([3])
mean_val = output.mean()
Drag options to blanks, or click blank then click option'
A1d
Bx
C20
D3d
Attempts:
3 left
💡 Hint
Common Mistakes
Using BatchNorm3d for 1D data.
Passing wrong variable names.