Are you sure you want to delete this access key?
Classic with PyTorch Tensor | PyTorch Enhanced |
---|---|
import torch | |
t_c = [0.5, 14.0, 15.0, 28.0, 11.0, 8.0, 3.0, -4.0, 6.0, 13.0, 21.0] t_u = [35.7, 55.9, 58.2, 81.9, 56.3, 48.9, 33.9, 21.8, 48.4, 60.4, 68.4] t_c = torch.tensor(t_c) t_u = torch.tensor(t_u) |
|
def model(t_u, w, b): return w * t_u + b |
|
def loss_fn(t_p, t_c): squared_diffs = (t_p - t_c)**2 return squared_diffs.mean() |
|
w = torch.ones(()) b = torch.zeros(()) print(w, b) t_p = model(t_u, w, b) |
params = torch.tensor([1.0, 0.0], requires_grad=True) params.grad is None |
loss = loss_fn(t_p, t_c) | loss = loss_fn(model(t_u, *params), t_c) loss.backward() params.grad |
elta = 0.1 learning_rate = 1e-2 |
Press p or to see the previous file or, n or to see the next file
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?