1
00:00:00,910 --> 00:00:10,930
Now, what we will do is we will take the, um, well, this example and we will apply it using PyTorch.

2
00:00:10,930 --> 00:00:14,560
We will see how simple it is to do so.

3
00:00:14,560 --> 00:00:18,520
So we first start with this, um.

4
00:00:20,250 --> 00:00:26,250
Just, uh, Jupyter Notebook and we call it, let's say basic.

5
00:00:27,950 --> 00:00:28,310
Three.

6
00:00:28,310 --> 00:00:31,760
This is the third or I don't know, we can call it actually back.

7
00:00:32,660 --> 00:00:35,960
For back propagation.

8
00:00:36,760 --> 00:00:38,440
And main.

9
00:00:39,260 --> 00:00:42,410
So we start with X.

10
00:00:43,260 --> 00:00:44,130
X and y.

11
00:00:44,160 --> 00:00:48,180
Of course x or not actually import import.

12
00:00:50,040 --> 00:00:51,030
Torch.

13
00:00:52,830 --> 00:00:57,660
And we start with defining x x equals.

14
00:00:58,960 --> 00:01:00,040
Torch.

15
00:01:00,760 --> 00:01:02,290
Dot tensor.

16
00:01:03,410 --> 00:01:05,630
Of the value.

17
00:01:06,640 --> 00:01:09,580
Of the value of x, which is.

18
00:01:10,980 --> 00:01:12,690
Which is one.

19
00:01:14,070 --> 00:01:17,910
And why is going to be.

20
00:01:19,800 --> 00:01:20,880
Equals.

21
00:01:22,910 --> 00:01:26,420
The tensor of value of two.

22
00:01:29,000 --> 00:01:34,520
On the other hand, w w is a little bit.

23
00:01:35,580 --> 00:01:36,870
A different.

24
00:01:37,050 --> 00:01:38,910
Let's let's see how we will identify.

25
00:01:39,120 --> 00:01:41,880
It will be torch dot.

26
00:01:45,690 --> 00:01:46,530
Tensor.

27
00:01:46,560 --> 00:01:47,550
Tensor.

28
00:01:48,030 --> 00:01:50,970
And then we will give it an initial value.

29
00:01:50,970 --> 00:01:52,860
In our case we give it one.

30
00:01:53,220 --> 00:01:58,710
And then we will say require requires gradient.

31
00:01:58,710 --> 00:02:00,870
Gradient equals true.

32
00:02:02,310 --> 00:02:07,110
And we shift enter if you print these values.

33
00:02:07,110 --> 00:02:12,150
So x print y print.

34
00:02:13,660 --> 00:02:15,760
W we see how they look.

35
00:02:16,180 --> 00:02:22,030
X and y is just a tensor and w is a tensor, but it says required gradient.

36
00:02:22,030 --> 00:02:29,350
So in the operations we will do to the w it will compute the d w over.

37
00:02:29,350 --> 00:02:33,490
You know, the thing we are connecting it with in our case is the loss.

38
00:02:34,610 --> 00:02:38,150
Now what we need to do is to do the operations.

39
00:02:38,150 --> 00:02:39,830
We said that.

40
00:02:40,950 --> 00:02:42,090
Operations is.

41
00:02:42,090 --> 00:02:51,000
The first one is w multiplied x will equal y hat y hat minus y will equal s, and s squared will equal

42
00:02:51,000 --> 00:02:51,840
loss.

43
00:02:51,840 --> 00:02:53,760
So we do the same thing.

44
00:02:54,240 --> 00:03:06,000
Y hat y hat equals w multiplied x s equals w or y hat.

45
00:03:06,950 --> 00:03:13,910
Minus y and loss will equal s.

46
00:03:15,810 --> 00:03:16,470
Squared.

47
00:03:17,170 --> 00:03:20,230
So these are just the operations we have done.

48
00:03:22,110 --> 00:03:27,600
And then we put shift enter and then we have the actual loss.

49
00:03:27,660 --> 00:03:35,760
So we said the first we go forward uh operation and then we can calculate the loss.

50
00:03:35,760 --> 00:03:38,460
So how much is the loss in this case.

51
00:03:38,460 --> 00:03:43,830
Well actually we already did the computation and the already computed this value.

52
00:03:43,830 --> 00:03:48,390
So we just, uh, print and we just print the loss.

53
00:03:48,630 --> 00:03:49,830
What do we have?

54
00:03:49,830 --> 00:03:52,800
We have the loss equals one.

55
00:03:52,830 --> 00:04:00,330
Of course, if we want to just show the value item and we just put like this and we will get it.

56
00:04:00,480 --> 00:04:01,350
Uh, like this.

57
00:04:01,350 --> 00:04:04,050
Of course the uh, loss is also a tensor.

58
00:04:04,560 --> 00:04:07,080
So here is we put it an item.

59
00:04:07,080 --> 00:04:11,100
And now we are having the forward pass value.

60
00:04:11,100 --> 00:04:12,870
How about the backward pass.

61
00:04:12,870 --> 00:04:14,850
Well, in PyTorch is very simple.

62
00:04:14,850 --> 00:04:16,860
We just one command.

63
00:04:16,860 --> 00:04:24,810
We just say loss dot back forward and that's it.

64
00:04:25,260 --> 00:04:26,850
And shift enter.

65
00:04:27,540 --> 00:04:28,470
That's it.

66
00:04:29,120 --> 00:04:32,750
But what does it what did it do it actually?

67
00:04:32,750 --> 00:04:34,460
Or how did the.

68
00:04:35,130 --> 00:04:37,620
Loss and W got calculated.

69
00:04:37,620 --> 00:04:43,290
Actually, we use the loss to make a backward, uh, propagation.

70
00:04:43,290 --> 00:04:51,630
And then he used these operations to go back to uh w which has the gradient equals to true.

71
00:04:52,250 --> 00:04:58,550
If we have more gradients, then it will calculate the loss and how everything is, uh, how the loss

72
00:04:58,550 --> 00:05:00,830
will change with every W we have.

73
00:05:00,830 --> 00:05:05,090
So print let's, let's see the results w.

74
00:05:05,090 --> 00:05:08,210
But this time we need to say gradient.

75
00:05:08,950 --> 00:05:10,690
And then we shift into.

76
00:05:10,930 --> 00:05:17,290
Of course we can just also print w like this, but we will see only the value of w.

77
00:05:17,320 --> 00:05:22,060
In order to get the gradient value we just put dot gradient.

78
00:05:22,210 --> 00:05:27,160
So with this way of course we have this value.

79
00:05:27,160 --> 00:05:29,740
Of course as a tensor we can also item.

80
00:05:30,520 --> 00:05:32,890
And do like this, but I prefer.

81
00:05:32,920 --> 00:05:34,450
Okay, let's let's do.

82
00:05:35,570 --> 00:05:37,190
The Or, let's put it.

83
00:05:38,030 --> 00:05:42,950
Two print statements because usually it's better just this way.

84
00:05:43,280 --> 00:05:53,810
So minus two, which is d loss over d w is what we calculated by hand which is this one minus two.
