finished chapter 5
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import torch
|
||||
|
||||
x = torch.tensor(1.0)
|
||||
y = torch.tensor(2.0)
|
||||
|
||||
w = torch.tensor(1.0, requires_grad=True)
|
||||
|
||||
#forward path and compute loss
|
||||
y_hat = w*x
|
||||
loss = (y_hat-y)**2
|
||||
|
||||
print(loss)
|
||||
|
||||
#backward path
|
||||
loss.backward()
|
||||
print(w.grad)
|
||||
|
||||
### update weights
|
||||
### next forward and backwards
|
||||
Reference in New Issue
Block a user