-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hi,
I'm encountering an issue during the training phase when using binary_cross_entropy_with_logits for binary classification. The error traceback is as follows:
ValueError: Target size (torch.Size([2])) must be the same as input size (torch.Size([2, 2]))
This error arises when I call the trainer.fit() method. From what I understand, the target size should match the input size produced by the model. However, in my case, it seems that the model is outputting a tensor of size [2, 2] instead of the expected [2].
Here is the relevant part of my code:
self.classifier = torch.nn.Linear(512, num_labels)
In my use case, num_labels is set to 2 for binary classification. I believe the issue might be related to how the model outputs are structured, given that binary classification typically expects a single output per instance rather than multiple logits.
Could you please advise on how to adjust the model or the loss function so that the target and input sizes match correctly for binary classification? Should I modify the classifier layer to output a single value (using num_labels=1) and then apply a sigmoid activation?
Any guidance on this would be greatly appreciated!
Thanks in advance.