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 torch
import torch.nn as nn
lin = nn.Linear(10,20)
manual_weights = torch.arange(20*10).reshape(lin.weight.shape)
lin.weight.data[:]= manual_weights
lin.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 sc1
sc1.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)
give me the correct output and explain what is this sc1 and where and why are we using

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

Step: 3

blur-text-image

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

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions

Question

Has your organisation defined its purpose, vision and mission?

Answered: 1 week ago