Created
January 27, 2020 13:49
-
-
Save aravindpai/574586f16f328d890baa8f5864311412 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 evaluate(model, iterator, criterion): | |
#initialize every epoch | |
epoch_loss = 0 | |
epoch_acc = 0 | |
#deactivating dropout layers | |
model.eval() | |
#deactivates autograd | |
with torch.no_grad(): | |
for batch in iterator: | |
#retrieve text and no. of words | |
text, text_lengths = batch.text | |
#convert to 1d tensor | |
predictions = model(text, text_lengths).squeeze() | |
#compute loss and accuracy | |
loss = criterion(predictions, batch.label) | |
acc = binary_accuracy(predictions, batch.label) | |
#keep track of loss and accuracy | |
epoch_loss += loss.item() | |
epoch_acc += acc.item() | |
return epoch_loss / len(iterator), epoch_acc / len(iterator) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment