I can definitely see why the conditionals are confusing the way I used them along with target. It was a mistake on my part. Instead of getting target from the dataloader, I was trying to figure it out using the conditionals. If data1 should be ranked higher, target=1, else 0. Is this a valid approach?
Thank you for your help. It makes sense. I just want to ask you a final question. When having multiple networks such as in this case, is it recommended that I have the same number of optimizers and do something like
optimizer1 = torch.optim.Adam(encoder_net.parameters(), lr=learning_rate)
optimizer2 = torch.optim.Adam(classifier_net.parameters(), lr=learning_rate)

…
optimizer1.zero_grad()
optimizer2.zero_grad()
optimizer1.step()
optimizer2.step()

or combine them into one:
optimizer = torch.optim.Adam
(
list(encoder_net.parameters()) + list(classifier_net.parameters()),
lr=learning_rate)
)

…
optimizer.zero_grad()
optimizer.step()