FeedForward Pytorch

Hi Team,

In the attached screenshot, I have two queries:-

a. Why we’re using mean to calculate accuracy? Accuracy is no. of correct predictions divided by total no. of predictions but I’m not getting why we’re taking mean here.

return (pred == y).float().mean()

b. Why we’re dividing weights by sqrt of 2 here? And what does requires_grad() function will do with the weights?

weights1 = torch.randn(2, 2) / math.sqrt(2)

weights2 = torch.randn(2, 4) / math.sqrt(2)

In the video, i’m not able to understand the explaination given. So, please provide a detailed explaination.

Thanks

Shweta

Hi Shweta,

  1. Here pred and y both are lists, and by doing pred==y, we’re getting a list with all binary values.
    If we do (pred==y).float().mean(), it calculates the number of 1s``` divided by total no. of elements in the list, which is same as what you mentioned:
  1. This is just a good practice to initialise random weights, You’ll get to learn a few of Weight Initializations sooner than later in the course itself.