Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions beginner_source/nn_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def nll(input, target):
yb = y_train[0:bs]
print(loss_func(preds, yb))

# Save the first batch for comparison after training
xb_initial = xb
yb_initial = yb


###############################################################################
# Let's also implement a function to calculate the accuracy of our model.
Expand Down Expand Up @@ -244,9 +248,10 @@ def accuracy(out, yb):
#
# Let's check the loss and accuracy and compare those to what we got
# earlier. We expect that the loss will have decreased and accuracy to
# have increased, and they have.
# have increased, and they have. We evaluate on the same initial batch
# we used before training for a fair comparison.

print(loss_func(model(xb), yb), accuracy(model(xb), yb))
print(loss_func(model(xb_initial), yb_initial), accuracy(model(xb_initial), yb_initial))

###############################################################################
# Using ``torch.nn.functional``
Expand Down