Jovian
⭐️
Sign In
In [1]:
import torch
In [2]:
x = torch.tensor([[3.,1.,4.],[5.,6.,7.]])
w = torch.tensor([[4.,6.],[7.,8.],[8.,10.]], requires_grad=True)
b = torch.tensor([5.,6.,7.], requires_grad=True)
In [4]:
y = torch.mm(w,x)
y = y.add(b)
y
Out[4]:
tensor([[ 47.,  46.,  65.],
        [ 66.,  61.,  91.],
        [ 79.,  74., 109.]], grad_fn=<AddBackward0>)
In [5]:
y.mean().backward()
In [6]:
print('dy/dx:', x.grad)
print('dy/dw:', w.grad)
print('dy/db:', b.grad)
dy/dx: None dy/dw: tensor([[0.8889, 2.0000], [0.8889, 2.0000], [0.8889, 2.0000]]) dy/db: tensor([0.3333, 0.3333, 0.3333])
In [ ]:
import jovian
jovian.commit()
[jovian] Please enter your API key (from https://jvn.io ): ········ [jovian] Saving notebook..
In [ ]: