Thanks a lot Ptrblck. Your answer worked with me.
Please help me with this error
TypeError: not all arguments converted during string formatting

Screen Shot 2021-10-19 at 5.29.34 PM1920×1359 149 KB


Screen Shot 2021-10-19 at 5.29.19 PM1916×1310 169 KB


Training function
for i in range(TRAIN_BATCH_SIZE):
    iter_loader1 = iter(training_loader1)
    batch1 = next(iter_loader1)
    iter_loader2 = iter(training_loader2)
    batch2 = next(iter_loader2)
    
    
    ids1 = batch1['ids'].to(device, dtype = torch.long)
    mask1 = batch1['mask'].to(device, dtype = torch.long)
    targets1 = batch1['targets'].to(device, dtype = torch.long)
    
    
    ids2 = batch2['ids'].to(device, dtype = torch.long)
    mask2 = batch2['mask'].to(device, dtype = torch.long)
    targets2 = batch2['targets'].to(device, dtype = torch.long)
    
    outputs = model(ids1, mask1, ids2, mask2)

    print(outputs)
    loss = loss_function(outputs, targets2)
    print(loss)
    tr_loss += loss.item()
    print(tr_loss)
    big_val, big_idx = torch.max(outputs.data, dim=1)
    print(big_val, big_idx)
    n_correct += calcuate_accu(big_idx, targets2)

    nb_tr_steps += 1
    print(nb_tr_steps)
    nb_tr_examples+=targets2.size(0)
    print(nb_tr_examples)
    #print (_)
    
    if _%100==0:
        loss_step = tr_loss/nb_tr_steps
        accu_step = (n_correct*100)/nb_tr_examples 
        print(f"Training Loss per 100 steps: {loss_step}")
        print(f"Training Accuracy per 100 steps: {accu_step}")

    optimizer.zero_grad()
    loss.backward()
    # # When using GPU
    optimizer.step()

print(f'The Total Accuracy for Epoch {epoch}: {(n_correct*100)/nb_tr_examples}')
epoch_loss = tr_loss/nb_tr_steps
epoch_accu = (n_correct*100)/nb_tr_examples
print(f"Training Loss Epoch: {epoch_loss}")
print(f"Training Accuracy Epoch: {epoch_accu}")

return