0
0
PyTorchml~10 mins

Forward pass, loss, backward, step 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 perform a forward pass using the model.

PyTorch
outputs = model([1])
Drag options to blanks, or click blank then click option'
Aloss
Blabels
Coptimizer
Dinputs
Attempts:
3 left
💡 Hint
Common Mistakes
Using labels instead of inputs for the forward pass.
Passing the optimizer to the model.
2fill in blank
medium

Complete the code to calculate the loss between outputs and labels.

PyTorch
loss = criterion(outputs, [1])
Drag options to blanks, or click blank then click option'
Alabels
Binputs
Coptimizer
Dmodel
Attempts:
3 left
💡 Hint
Common Mistakes
Using inputs instead of labels for loss calculation.
Passing the model or optimizer instead of labels.
3fill in blank
hard

Fix the error in the code to perform backpropagation.

PyTorch
loss.[1]()
Drag options to blanks, or click blank then click option'
Astep
Bbackward
Cforward
Dzero_grad
Attempts:
3 left
💡 Hint
Common Mistakes
Calling step() on loss instead of optimizer.
Calling zero_grad() on loss.
4fill in blank
hard

Fill both blanks to reset gradients and update model parameters.

PyTorch
optimizer.[1]()
optimizer.[2]()
Drag options to blanks, or click blank then click option'
Azero_grad
Bstep
Cbackward
Dforward
Attempts:
3 left
💡 Hint
Common Mistakes
Calling backward() or forward() on optimizer.
Not clearing gradients before the step.
5fill in blank
hard

Fill all three blanks to complete a training step: forward pass, loss calculation, and backward pass.

PyTorch
outputs = model([1])
loss = criterion(outputs, [2])
loss.[3]()
Drag options to blanks, or click blank then click option'
Ainputs
Blabels
Cbackward
Doptimizer
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up inputs and labels in loss calculation.
Forgetting to call backward on loss.