Created
June 8, 2019 19:31
-
-
Save vaibhavkumar049/186c01b37d24cfa31355e0d0d78025bd 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
def fit_v1(epochs = 1000, learning_rate = 1): | |
loss_arr = [] | |
acc_arr = [] | |
opt = optim.SGD(fn.parameters(), lr=learning_rate) | |
for epoch in range(epochs): | |
y_hat = fn(X_train) | |
loss = F.cross_entropy(y_hat, Y_train) | |
loss_arr.append(loss.item()) | |
acc_arr.append(accuracy(y_hat, Y_train)) | |
loss.backward() | |
opt.step() | |
opt.zero_grad() | |
plt.plot(loss_arr, 'r-') | |
plt.plot(acc_arr, 'b-') | |
plt.show() | |
print('Loss before training', loss_arr[0]) | |
print('Loss after training', loss_arr[-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment