In the training loop below, you can see that train_loss
represents the loss on the most recent batch.
Whereas the eval_loss
is computed on the entire training dataset.
When I print it out, should I be recalculating the train_loss
against the entire training split instead of the last batch?
for epoch in range(epochs):
# Loop over batches.
for i, batch in enumerate(samples_train['features']):
train_preds = model(samples_train['features'][i])
train_loss = loss_fn(train_preds, samples_train['labels'][i])
optimizer.zero_grad()
train_loss.backward()
optimizer.step()
# Only the training data is batched.
eval_preds = model(samples_evaluate['features'])
eval_loss = loss_fn(eval_preds, samples_evaluate['labels'])
print(f"Epoch: {epoch}, Train_Loss: {float(train_loss)}, Eval_Loss: {float(eval_loss)}")