Help with contrastive loss

Hi, I’m trying to apply the loss function but on a high-dim dataset which is a tabular one, not an image type. There may be 2 or more datasets which I want to bring together, as if it is a batch correction problem.

So if there are 2 datasets, each with 10 classes, if samples belong to the same class, whether they belong to the first data or second data, they should be closer together in latent space.

Problem is, there is a class imbalance…or label imbalance and I encountered the following error:
RuntimeError: The size of tensor a (56) must match the size of tensor b (3) at non-singleton dimension 0

So for instance, if dataset 1 has 100 samples of class 1, dataset 2 has only 5 samples of class 1. How do I resolve this if I don’t want to upsample or downsample?

If I am understanding this right you want to build a model and find its accuracy but there is a class imbalance between the different classes present.

In this case I think you should be using metrics such as precision, recall and F1 score. Just google them it could be helpful to your problem.

Not finding its accuracy for now. More of finding a new latent representation for both datasets or at least 1, such that whatever samples that belong to the same class will group more closely together in that space, which is the purpose of the loss function.