Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This challenge task is quite difficult and will really test your mastery of PyTorch and nn . Linear layers. We can manually assign weights to

This challenge task is quite difficult and will really test your mastery of PyTorch and nn.Linear layers.
We can manually assign weights to an nn.Linear like this:
import torchimport torch.nn as nnlin = nn.Linear(10,20)manual_weights = torch.arange(20*10).reshape(lin.weight.shape)lin.weight.data[:]= manual_weightslin.bias.data[:]=0
But this does not calculate anything useful. A Linear layer simply performs a weighted sum (plus bias). We can choose weights/biases to perform known operations.
INSTRUCTIONS:
Given an nn.Linear(1,1) layer, set the weights such that the layer adds 1 to it's input.
Given an nn.Linear(1,1) layer, set the weights such that the layer calculates y =3x +2.
Given an nn.Linear(4,1) layer, set the weights such that the layer calculates the average of it's inputs.
Given an nn.Linear(4,2) layer, set the weights such that the layer calculates both the average of it's inputs and the sum of the inputs.
Given an nn.Linear(3,3) layer, set the weights such that the layer returns the inputs, but in reverse order.
Given an nn.Linear(5,2) layer, set the weights such that the layer always returns (4,2)
Note: We would never use this in a deep learning model; this challenge is to prove that you understand the mathematics and coding mechanics of the nn.Linear layer.
import sc1sc1.test_1(sc1.modify_lin_1)sc1.test_2(sc1.modify_lin_2)sc1.test_3(sc1.modify_lin_3)sc1.test_4(sc1.modify_lin_4)sc1.test_5(sc1.modify_lin_5)sc1.test_6(sc1.modify_lin_6)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions