# loss_pos and loss_neg now contain the sum of positive and negative pair losses # as computed relative to the i'th input. loss_pos = loss_pos.sum(dim=1) loss_neg = loss_neg.sum(dim=1)