INNER CODE UNIT · Python
evaluate
barissayil/SentimentAnalysis · analyzer.py:58
def evaluate(self, val_loader, criterion):
# Set model to evaluation mode.
self.model.eval()
# Initialize batch accuracy summation, loss, and number of batches.
batch_accuracy_summation, loss, num_batches = 0, 0, 0
# Don't track gradient.
with torch.no_grad():
# Go through validation set in batches.
for input_ids, attention_mask, labels in tqdm(
val_loader, desc="Evaluating"
):
# Put input IDs, attention mask, and labels to device.
input_ids, attention_mask, labels = (
input_ids.to(self.device),
attention_mask.to(self.device),
labels.to(self.device),
)
# Get logits.