Created
October 31, 2021 00:34
-
-
Save b0noI/36b84dadba6ba5838329b09b85cb423b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
epoch = 100 | |
for _ in range(epoch): | |
for i in range(len(X)): | |
x, y = torch.tensor(X[i]), torch.tensor(Y[i]) | |
y_predict = model(x) | |
loss_tensor = loss(y_predict, y) | |
loss_tensor.backward() | |
loss_value = loss_tensor.data[0] | |
with torch.no_grad(): | |
w -= w.grad * 1e-3 | |
b -= b.grad * 1e-3 | |
w.grad.zero_() | |
b.grad.zero_() | |
print(loss_value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment