Pytorch: Reshape 1d to 2d target
Apologies if this has been answered already but I couldn't find it.
I have a binary classification problem which I have been using CrossEntropyLoss for which expects the following input and target tensor dimensions:

I have switched to using BCEWithLogitsLoss with pre-calculated class weights to address a label imbalance problem. The issue is BCEWithLogitsLoss expects the following dimensions:

How would I go about shaping my 1D tensor, ie. tensor([[0, 0, 0,  ..., 1, 0, 0]]) to the shape of my inputs which is (No. of X samples, 2)? I have tried .unsqueeze(1) but this gives me (#X, 1). To clarify, my input shape in the prior problem was [32,2] with target shape [32] as per above documentation and I am looking for [32,2] for both input and target dims.

I ended up figuring the problem out, didn't realise there was built-in one-hot encoding functionality in Pytorch.
I used the line torch.nn.functional.one_hot(targets) which reshaped my target variable to torch.Size([32, 2]).
